bpo-41249: Fix postponed annotations for TypedDict#27017
Conversation
There was a problem hiding this comment.
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.
Sorry, something went wrong.
|
@Fidget-Spinner, I added the tests, the news entry and fixed the |
Sorry, something went wrong.
Fidget-Spinner
left a comment
There was a problem hiding this comment.
LG in general! I just have a few non-code comments. Thanks :).
Sorry, something went wrong.
This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
|
@Fidget-Spinner, I made the suggested changes. Thank you for reviewing! 😃 |
Sorry, something went wrong.
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
gvanrossum
left a comment
There was a problem hiding this comment.
LG except I'd like the helper module renamed. Thanks!
Sorry, something went wrong.
septatrix
left a comment
There was a problem hiding this comment.
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
Sorry, something went wrong.
gvanrossum
left a comment
There was a problem hiding this comment.
Just one nit, I’ll commit the fix and then land.
Sorry, something went wrong.
|
@Kronuz congrats on landing your first PR in CPython :)! Great work! |
Sorry, something went wrong.
|
Yes, good work! |
Sorry, something went wrong.
|
Thanks @Kronuz for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, something went wrong.
|
Thanks @Kronuz for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, something went wrong.
|
Sorry, @Kronuz and @gvanrossum, I could not cleanly backport this to |
Sorry, something went wrong.
|
Sorry @Kronuz and @gvanrossum, I had trouble checking out the |
Sorry, something went wrong.
|
I'll look into it. |
Sorry, something went wrong.
|
Thanks @Kronuz for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, something went wrong.
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 <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 889036f) Co-authored-by: Germán Méndez Bravo <german.mb@gmail.com>
|
Seems like bedevere was just feeling a little unwell ;). |
Sorry, something went wrong.
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 <28750310+Fidget-Spinner@users.noreply.github.com>
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 <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 889036f) Co-authored-by: Germán Méndez Bravo <german.mb@gmail.com>
…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 <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Germán Méndez Bravo <german.mb@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Summary:
This fixes
TypedDictto work withget_type_hints()and postponed evaluation of annotations across modules.This is done by adding the module name to
ForwardRefat 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