Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properties and additionalProperties #7

Open
sbrunner opened this issue May 6, 2021 · 1 comment
Open

properties and additionalProperties #7

sbrunner opened this issue May 6, 2021 · 1 comment

Comments

@sbrunner
Copy link
Owner

sbrunner commented May 6, 2021

When we have properties and additionalProperties like:

{
  "propterites": {
    "id": {"type": "number"}
  },
  "additionalProperties": {"type": "string"}
}

It is interpreted as:

TypeTyped = TypedDict(
    "TypeTyped",
    {
        "type": Union[int, float]
    },
    totaf=False,
)

Type = Union[TypeTyped, Dict[str, str]]

But it's not entirely correct.

See also: python/mypy#6131

@Andrew-Chen-Wang
Copy link

There are two options here:

  • Per recommendation by GvR, we could use dataclasses but that would break quite a bit of things
  • The other way is to subclass dataclasses or NamedTuple that defines __getattr__ so that one can do var[field].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants