-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
bpo-41249: Fix postponed annotations for TypedDict #27017
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this fix! Some general comments:
- Please add your proposed tests. Tests for typing are at https://github.com/python/cpython/blob/main/Lib/test/test_typing.py. Since your tests require multiple files, you can create them in that folder, or reuse this file that's used for testing type annotations in separate modules https://github.com/python/cpython/blob/main/Lib/test/mod_generics_cache.py)
- Please add a news entry via blurb.
I'll try to do a full review later.
@Fidget-Spinner, I added the tests, the news entry and fixed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG in general! I just have a few non-code comments. Thanks :).
Misc/NEWS.d/next/Library/2021-07-04-11-33-34.bpo-41249.sHdwBE.rst
Outdated
Show resolved
Hide resolved
This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the quick response!
Please don't force push in the future. It overwrites valuable history, and besides, the core devs will squash and merge your PR as a single commit :).
I can't merge your PR, so I'll wait for Guido or some other core dev to review. If no one tends to this in a week or two, please gently ping the issue tracker.
Misc/NEWS.d/next/Library/2021-07-04-11-33-34.bpo-41249.sHdwBE.rst
Outdated
Show resolved
Hide resolved
@Fidget-Spinner, I made the suggested changes. Thank you for reviewing! 😃 |
Co-authored-by: Ken Jin <[email protected]>
Co-authored-by: Ken Jin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG except I'd like the helper module renamed. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think it would be beneficial to figure out why TypedDicts have no MRO as this would trivially solve this problem. That being said I think this is a rather clean workaround for the time being
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one nit, I’ll commit the fix and then land.
@Kronuz congrats on landing your first PR in CPython :)! Great work! |
Yes, good work! |
Thanks @Kronuz for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Thanks @Kronuz for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, @Kronuz and @gvanrossum, I could not cleanly backport this to |
Sorry @Kronuz and @gvanrossum, I had trouble checking out the |
I'll look into it. |
Thanks @Kronuz for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules. This is done by adding the module name to ForwardRef at the time the object is created and using that to resolve the globals during the evaluation. Co-authored-by: Ken Jin <[email protected]> (cherry picked from commit 889036f) Co-authored-by: Germán Méndez Bravo <[email protected]>
Seems like bedevere was just feeling a little unwell ;). |
This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules. This is done by adding the module name to ForwardRef at the time the object is created and using that to resolve the globals during the evaluation. Co-authored-by: Ken Jin <[email protected]>
This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules. This is done by adding the module name to ForwardRef at the time the object is created and using that to resolve the globals during the evaluation. Co-authored-by: Ken Jin <[email protected]> (cherry picked from commit 889036f) Co-authored-by: Germán Méndez Bravo <[email protected]>
…H-27205) This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules. This is done by adding the module name to ForwardRef at the time the object is created and using that to resolve the globals during the evaluation. Co-authored-by: Ken Jin <[email protected]> Co-authored-by: Germán Méndez Bravo <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
Summary:
This fixes
TypedDict
to work withget_type_hints()
and postponed evaluation of annotations across modules.This is done by adding the module name to
ForwardRef
at the time the object is created and using that to resolve the globals during the evaluation.Test Plan:
Having these two file:
Before:
After:
https://bugs.python.org/issue41249