]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-133960: Improve typing.evaluate_forward_ref (#133961)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Sun, 25 May 2025 17:26:39 +0000 (10:26 -0700)
committerGitHub <noreply@github.com>
Sun, 25 May 2025 17:26:39 +0000 (17:26 +0000)
commit57fef27cfc2bdfc1e3a65ef8c8a760198d15b14d
tree3f3bcaea9b560b56838e63b4937912cd90b9dc57
parentb51b08a0a5fedde4f74e4cc338b8b5ad9656ad50
gh-133960: Improve typing.evaluate_forward_ref (#133961)

As explained in #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 #133959 as a side effect, because the buggy behavior in #133959 derives from
evaluate_forward_ref().
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]