bpo-41249: Fix postponed annotations for TypedDict#27017
bpo-41249: Fix postponed annotations for TypedDict#27017gvanrossum merged 6 commits intopython:mainfrom
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.
|
@Fidget-Spinner, I added the tests, the news entry and fixed the |
Fidget-Spinner
left a comment
There was a problem hiding this comment.
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.
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 <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!
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
gvanrossum
left a comment
There was a problem hiding this comment.
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. |
|
GH-27204 is a backport of this pull request to the 3.10 branch. |
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 ;). |
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