]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-133960: Improve typing.evaluate_forward_ref (GH-133961) (#134663)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 25 May 2025 17:52:04 +0000 (19:52 +0200)
committerGitHub <noreply@github.com>
Sun, 25 May 2025 17:52:04 +0000 (17:52 +0000)
commit9c6d2dbe26e30114773bf55147d36960cb89e519
tree07f3e026a41f0ef7a1fb6c938ddfb2e16bec1d26
parent8c6653428f32189e4779a5ed444cf42e811368e0
[3.14] gh-133960: Improve typing.evaluate_forward_ref (GH-133961) (#134663)

gh-133960: Improve typing.evaluate_forward_ref (GH-133961)

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 57fef27cfc2bdfc1e3a65ef8c8a760198d15b14d)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Doc/library/typing.rst
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2025-05-12-20-38-57.gh-issue-133960.Aee79f.rst [new file with mode: 0644]