Commit a4a6976
committed
gh-140665: Substitute PEP 696 defaults referencing other parameters
A type parameter's default may reference an earlier parameter in the same scope (e.g. class C[T, S = T], or S = list[T]), but the default was inserted unsubstituted when a trailing parameter was filled from it. Parametrizing C[int] produced C[int, T] instead of C[int, int], leaking the unbound type variable; nested defaults (S = list[T]) and chained defaults (S = T, U = S) were left unbound too.
Add _resolve_parameter_defaults, called from _generic_class_getitem and _GenericAlias._determine_new_args, which substitutes the now-bound parameters into any argument supplied by a default. Detection is gated on the argument tuple growing during __typing_prepare_subst__, so explicitly-passed arguments such as C[int, T] are left untouched.1 parent e51b616 commit a4a6976
3 files changed
Lines changed: 83 additions & 0 deletions
File tree
- Lib
- test
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
706 | 706 | | |
707 | 707 | | |
708 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
709 | 739 | | |
710 | 740 | | |
711 | 741 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1138 | 1138 | | |
1139 | 1139 | | |
1140 | 1140 | | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
1141 | 1175 | | |
1142 | 1176 | | |
1143 | 1177 | | |
| |||
1182 | 1216 | | |
1183 | 1217 | | |
1184 | 1218 | | |
| 1219 | + | |
1185 | 1220 | | |
1186 | 1221 | | |
1187 | 1222 | | |
| 1223 | + | |
1188 | 1224 | | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
1189 | 1228 | | |
| 1229 | + | |
| 1230 | + | |
1190 | 1231 | | |
1191 | 1232 | | |
1192 | 1233 | | |
| |||
1450 | 1491 | | |
1451 | 1492 | | |
1452 | 1493 | | |
| 1494 | + | |
1453 | 1495 | | |
1454 | 1496 | | |
1455 | 1497 | | |
| 1498 | + | |
1456 | 1499 | | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
1457 | 1503 | | |
1458 | 1504 | | |
1459 | 1505 | | |
1460 | 1506 | | |
1461 | 1507 | | |
| 1508 | + | |
| 1509 | + | |
1462 | 1510 | | |
1463 | 1511 | | |
1464 | 1512 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments