You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypedDict inheritance doesn't work with get_type_hints and postponed evaluation of annotations across modules #737
Thus, get_type_hints is unable to resolve the types for annotations that are only imported in foo.py.
I ran this example using typing_extensions 3.7.4.2 (released via #709) and Python 3.7.3, but it seems like this would be an issue using the current main branches of both repositories as well.
I'm wondering what the right approach is to tackling this issue. It is of course solvable by defining Bar in foo.py instead, but it isn't ideal or intuitive to always need to inherit from a TypedDict in the same module.
I was thinking that similarly to __required_keys__ and __optional_keys__, the TypedDict could preserve its original bases in a new dunder attribute, and get_type_hints could work off of that instead of MRO when it is dealing with a TypedDict. I would be willing to contribute the PRs to implement this if the design is acceptable, but am open to other ideas as well.
Hi @keithblaha, can you also file this on bugs.python.org? It is relevant for Python 3.10 which will turn on this behavior by default. (In fact it probably isn't going to be fixed anywhere except in the 3.9 and 3.10 stdlib versions of typing.py -- and maybe 3.8.)
Activity
gvanrossum commentedon Jul 8, 2020
Hi @keithblaha, can you also file this on bugs.python.org? It is relevant for Python 3.10 which will turn on this behavior by default. (In fact it probably isn't going to be fixed anywhere except in the 3.9 and 3.10 stdlib versions of typing.py -- and maybe 3.8.)
keithblaha commentedon Jul 8, 2020
Filed: https://bugs.python.org/issue41249
srittau commentedon Nov 4, 2021
Thanks, closing this here.