]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-137226: Fix get_type_hints() on generic TypedDict with stringified annotations...
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Tue, 16 Sep 2025 14:28:39 +0000 (07:28 -0700)
committerGitHub <noreply@github.com>
Tue, 16 Sep 2025 14:28:39 +0000 (07:28 -0700)
commit6d6aba252301cdf9d5ae3189629e1e43101dd58f
treedd9c6d43918e8efcec06b816186005ec8f24b85a
parentab6893ab5c04fecf71c94f7d65527df124155df5
gh-137226: Fix get_type_hints() on generic TypedDict with stringified 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.
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2025-09-15-13-09-19.gh-issue-137226.HH3_ik.rst [new file with mode: 0644]