-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-137226: Fix behavior of ForwardRef.evaluate with type_params #137227
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
The previous behavior was copied from earlier typing code. It works around the way typing.get_type_hints passes its namespaces, but I don't think the behavior is logical or correct.
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'm not a domain expert but this seems correct, if kludgy, to me. (To be honest, it's not more of a kludge than the old implementation.)
|
Thanks for reviewing! I think the annotationlib code is less kludgy; the typing code is more kludgy but that's for compatibility with old |
|
Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…pythonGH-137227) The previous behavior was copied from earlier typing code. It works around the way typing.get_type_hints passes its namespaces, but I don't think the behavior is logical or correct. (cherry picked from commit 089a324) Co-authored-by: Jelle Zijlstra <[email protected]>
|
GH-137709 is a backport of this pull request to the 3.14 branch. |
GH-137227) (#137709) Co-authored-by: Jelle Zijlstra <[email protected]>
…python#137227) The previous behavior was copied from earlier typing code. It works around the way typing.get_type_hints passes its namespaces, but I don't think the behavior is logical or correct.
…_params (pythonGH-137227) (python#137709) Co-authored-by: Jelle Zijlstra <[email protected]>
…gified annotations This issue appears specifically for TypedDicts because the TypedDict constructor code converts string annotations to ForwardRef objects, and those are not evaluated properly by the get_type_hints() stack because of other shenanigans with type parameters. This issue does not affect normal generic classes because their annotations are not pre-converted to ForwardRefs. The fix attempts to restore the pre- python#137227 behavior in the narrow scenario where the issue manifests. It mostly makes changes only in the paths accessible from get_type_hints(), ensuring that newer APIs (such as evaluate_forward_ref() and annotationlib) are not affected by get_type_hints()'s past odd choices. This PR does not fix python#138949, an older issue I discovered while playing around with this one; we'll need a separate and perhaps more invasive fix for that, but it should wait until after 3.14.0.
… annotations (#138953) This issue appears specifically for TypedDicts because the TypedDict constructor code converts string annotations to ForwardRef objects, and those are not evaluated properly by the get_type_hints() stack because of other shenanigans with type parameters. This issue does not affect normal generic classes because their annotations are not pre-converted to ForwardRefs. The fix attempts to restore the pre- #137227 behavior in the narrow scenario where the issue manifests. It mostly makes changes only in the paths accessible from get_type_hints(), ensuring that newer APIs (such as evaluate_forward_ref() and annotationlib) are not affected by get_type_hints()'s past odd choices. This PR does not fix issue #138949, an older issue I discovered while playing around with this one; we'll need a separate and perhaps more invasive fix for that, but it should wait until after 3.14.0.
…h stringified annotations (pythonGH-138953) This issue appears specifically for TypedDicts because the TypedDict constructor code converts string annotations to ForwardRef objects, and those are not evaluated properly by the get_type_hints() stack because of other shenanigans with type parameters. This issue does not affect normal generic classes because their annotations are not pre-converted to ForwardRefs. The fix attempts to restore the pre- pythonGH-137227 behavior in the narrow scenario where the issue manifests. It mostly makes changes only in the paths accessible from get_type_hints(), ensuring that newer APIs (such as evaluate_forward_ref() and annotationlib) are not affected by get_type_hints()'s past odd choices. This PR does not fix issue pythonGH-138949, an older issue I discovered while playing around with this one; we'll need a separate and perhaps more invasive fix for that, but it should wait until after 3.14.0. (cherry picked from commit 6d6aba2) Co-authored-by: Jelle Zijlstra <[email protected]>
The previous behavior was copied from earlier typing code. It works around the way
typing.get_type_hints passes its namespaces, but I don't think the behavior is logical
or correct.