Commit 25ab548
committed
[3.14] pythongh-137226: Fix get_type_hints() on generic TypedDict with stringified annotations (pythonGH-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- pythonGH-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 pythonGH-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.
(cherry picked from commit 6d6aba2)
Co-authored-by: Jelle Zijlstra <[email protected]>1 parent 284ab76 commit 25ab548
File tree
3 files changed
+39
-12
lines changed- Lib
- test
- Misc/NEWS.d/next/Library
3 files changed
+39
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7132 | 7132 | | |
7133 | 7133 | | |
7134 | 7134 | | |
| 7135 | + | |
| 7136 | + | |
| 7137 | + | |
| 7138 | + | |
| 7139 | + | |
| 7140 | + | |
| 7141 | + | |
| 7142 | + | |
| 7143 | + | |
| 7144 | + | |
| 7145 | + | |
| 7146 | + | |
| 7147 | + | |
7135 | 7148 | | |
7136 | 7149 | | |
7137 | 7150 | | |
| |||
8668 | 8681 | | |
8669 | 8682 | | |
8670 | 8683 | | |
8671 | | - | |
8672 | | - | |
| 8684 | + | |
| 8685 | + | |
8673 | 8686 | | |
8674 | 8687 | | |
8675 | 8688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
446 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
447 | 449 | | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
448 | 460 | | |
449 | 461 | | |
450 | 462 | | |
| |||
465 | 477 | | |
466 | 478 | | |
467 | 479 | | |
468 | | - | |
| 480 | + | |
469 | 481 | | |
470 | 482 | | |
471 | 483 | | |
| |||
2347 | 2359 | | |
2348 | 2360 | | |
2349 | 2361 | | |
2350 | | - | |
| 2362 | + | |
2351 | 2363 | | |
2352 | 2364 | | |
2353 | 2365 | | |
| |||
2392 | 2404 | | |
2393 | 2405 | | |
2394 | 2406 | | |
2395 | | - | |
| 2407 | + | |
2396 | 2408 | | |
2397 | 2409 | | |
2398 | 2410 | | |
| |||
3128 | 3140 | | |
3129 | 3141 | | |
3130 | 3142 | | |
3131 | | - | |
| 3143 | + | |
3132 | 3144 | | |
3133 | 3145 | | |
3134 | 3146 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
0 commit comments