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

TypedDict: Resolve string-based annotations #60

Closed
wants to merge 1 commit into from

Conversation

d-k-bo
Copy link
Contributor

@d-k-bo d-k-bo commented Jul 27, 2022

Fixes #55

I'm calling typing.get_type_hints because typing_extensions.get_type_hints is not yet defined in the relevant section. This shouldn't be a problem as long the behaviour of get_type_hints(..., include_extras=True) doesn't change. When porting this to the typing module, it should work fine because the definition order is fine there.

The test on Python 3.11 fails because TypedDict is rexported from typing (it took some time until I realized that this was the problem :D).

@JelleZijlstra
Copy link
Member

I don't think we should do this, since get_type_hints() can and will throw errors for some TypedDicts.

@d-k-bo
Copy link
Contributor Author

d-k-bo commented Jul 28, 2022

It seems like I underestimated the current limitations of get_type_hints.

Possible cases where it fails:

These are pretty common patterns and I can see that this would be unacceptable.

It might be better to evaluate the annotations on a per-item basis with a fallback in case of failure.

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

Successfully merging this pull request may close these issues.

Required/NotRequired don't work with __future__.annotations
2 participants