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
TypedDict(...) as function does not respect "total" when setting __required_keys__ and __optional_keys__ #86225
Comments
>>> DummyDict = TypedDict('DummyDict', {'x': int, 'y': str}, total=False)
>>> DummyDict.__required_keys__
frozenset({'x', 'y'}) This happens because the TypedDict function does not pass the "total" metaclass argument to _TypedDictMeta() (instead passing "__total__" in the attribute namespace) and the new code that sets __required_keys__ and __optional_keys__ only checks the metaclass argument. |
Can you submit a PR to fix this? It looks like you already have a good understanding of the root cause of the problem, so it should be easy to fix. (Be sure to add a unit test.) It can be backported to earlier Python versions that have typing.TypedDict (3.8+). |
Whoops, sorry, didn't see that you already have a PR. I'll review it next week during the core sprint. |
Looking for another reviewer. |
We're looking for a volunteer to port this code to typing_extensions: |
I have backported this to typing_extensions in python/typing#778 On Python 3.9.2 and above typing.TypedDict is used, otherwise it's typing_extensions.TypedDict. |
Dominic, thanks so much for the backport! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: