KEMBAR78
[3.14] gh-133960: Improve typing.evaluate_forward_ref (GH-133961) by miss-islington · Pull Request #134663 · python/cpython · GitHub
Skip to content

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