10000 [3.14] gh-133960: Improve typing.evaluate_forward_ref (GH-133961) by miss-islington · Pull Request #134663 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.14] gh-133960: Improve typing.evaluate_forward_ref (GH-133961) #134663

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

Merged
merged 1 commit into from
May 25, 2025

Conversation

miss-islington
Copy link
Contributor
@miss-islington miss-islington commented May 25, 2025

As explained in GH-133960, this removes most of the behavior differences with ForwardRef.evaluate.
The remaining difference is about recursive evaluation of forwardrefs; this is practically useful
in cases where an annotation refers to a type alias that itself is string-valued.

This also improves several edge cases that were previously not handled optimally. For example,
the function now takes advantage of the partial evaluation behavior of ForwardRef.evaluate() to
evaluate more ForwardRefs in the FORWARDREF format.

This also fixes GH-133959 as a side effect, because the buggy behavior in GH-133959 derives from
evaluate_forward_ref().
(cherry picked from commit 57fef27)

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com


📚 Documentation preview 📚: https://cpython-previews--134663.org.readthedocs.build/

As explained in pythonGH-133960, this removes most of the behavior differences with ForwardRef.evaluate.
The remaining difference is about recursive evaluation of forwardrefs; this is practically useful
in cases where an annotation refers to a type alias that itself is string-valued.

This also improves several edge cases that were previously not handled optimally. For example,
the function now takes advantage of the partial evaluation behavior of ForwardRef.evaluate() to
evaluate more ForwardRefs in the FORWARDREF format.

This also fixes pythonGH-133959 as a side effect, because the buggy behavior in pythonGH-133959 derives from
evaluate_forward_ref().
(cherry picked from commit 57fef27)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@JelleZijlstra JelleZijlstra enabled auto-merge (squash) May 25, 2025 17:39
@JelleZijlstra JelleZijlstra merged commit 9c6d2db into python:3.14 May 25, 2025
44 checks passed
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.

2 participants
0