Skip to content

TypedDict: Resolve string-based annotations - #60

Closed
d-k-bo wants to merge 1 commit into
python:mainfrom
d-k-bo:typeddict-string-annotations
Closed

d-k-bo wants to merge 1 commit into
python:mainfrom
d-k-bo:typeddict-string-annotations

Conversation

@d-k-bo

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@d-k-bo

d-k-bo commented Jul 28, 2022

Copy link
Copy Markdown
Contributor Author

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