Skip to content

Commit 017ec6b

Browse files
committed
Sync canonical typing repr tests with Python 3.15 final
Copy six complete test definitions from CPython d220409a13b77de7a6c30abe16ea90db01528edc using scripts/update_lib copy-test with source and destination SHA256 pins. Preserve all surrounding tests and markers; no manual assertion edits or skips. AI assistance: OpenAI Codex diagnosed old expected representations, performed the official copies and independent provenance review, and ran the six exact tests with the existing candidate release binary. All six pass; full suites were not rerun locally. Assisted-by: OpenAI Codex:model version unavailable
1 parent 8dc8a78 commit 017ec6b

2 files changed

Lines changed: 35 additions & 33 deletions

File tree

‎Lib/test/test_type_aliases.py‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,31 +144,33 @@ def test_subscripting(self):
144144

145145
def test_repr(self):
146146
type Simple = int
147-
type VeryGeneric[T, *Ts, **P] = Callable[P, tuple[T, *Ts]]
147+
self.assertEqual(repr(Simple), Simple.__qualname__)
148148

149-
self.assertEqual(repr(Simple), "Simple")
150-
self.assertEqual(repr(VeryGeneric), "VeryGeneric")
149+
type VeryGeneric[T, *Ts, **P] = Callable[P, tuple[T, *Ts]]
150+
self.assertEqual(repr(VeryGeneric), VeryGeneric.__qualname__)
151+
fullname = f"{VeryGeneric.__module__}.{VeryGeneric.__qualname__}"
151152
self.assertEqual(repr(VeryGeneric[int, bytes, str, [float, object]]),
152-
"VeryGeneric[int, bytes, str, [float, object]]")
153+
f"{fullname}[int, bytes, str, [float, object]]")
153154
self.assertEqual(repr(VeryGeneric[int, []]),
154-
"VeryGeneric[int, []]")
155+
f"{fullname}[int, []]")
155156
self.assertEqual(repr(VeryGeneric[int, [VeryGeneric[int], list[str]]]),
156-
"VeryGeneric[int, [VeryGeneric[int], list[str]]]")
157+
f"{fullname}[int, [{fullname}[int], list[str]]]")
157158

158159
def test_recursive_repr(self):
159160
type Recursive = Recursive
160-
self.assertEqual(repr(Recursive), "Recursive")
161+
self.assertEqual(repr(Recursive), Recursive.__qualname__)
161162

162163
type X = list[Y]
163164
type Y = list[X]
164-
self.assertEqual(repr(X), "X")
165-
self.assertEqual(repr(Y), "Y")
165+
self.assertEqual(repr(X), X.__qualname__)
166+
self.assertEqual(repr(Y), Y.__qualname__)
166167

167168
type GenericRecursive[X] = list[X | GenericRecursive[X]]
168-
self.assertEqual(repr(GenericRecursive), "GenericRecursive")
169-
self.assertEqual(repr(GenericRecursive[int]), "GenericRecursive[int]")
169+
self.assertEqual(repr(GenericRecursive), GenericRecursive.__qualname__)
170+
fullname = f"{GenericRecursive.__module__}.{GenericRecursive.__qualname__}"
171+
self.assertEqual(repr(GenericRecursive[int]), f"{fullname}[int]")
170172
self.assertEqual(repr(GenericRecursive[GenericRecursive[int]]),
171-
"GenericRecursive[GenericRecursive[int]]")
173+
f"{fullname}[{fullname}[int]]")
172174

173175
def test_raising(self):
174176
type MissingName = list[_My_X]

‎Lib/test/test_typing.py‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,16 +1432,16 @@ def test_repr_is_correct(self):
14321432
class G1(Generic[*Ts]): pass
14331433
class G2(Generic[Unpack[Ts]]): pass
14341434

1435-
self.assertEqual(repr(Ts), 'Ts')
1435+
self.assertEqual(repr(Ts), '~Ts')
14361436

1437-
self.assertEqual(repr((*Ts,)[0]), 'typing.Unpack[Ts]')
1438-
self.assertEqual(repr(Unpack[Ts]), 'typing.Unpack[Ts]')
1437+
self.assertEqual(repr((*Ts,)[0]), 'typing.Unpack[~Ts]')
1438+
self.assertEqual(repr(Unpack[Ts]), 'typing.Unpack[~Ts]')
14391439

1440-
self.assertEqual(repr(tuple[*Ts]), 'tuple[typing.Unpack[Ts]]')
1441-
self.assertEqual(repr(Tuple[Unpack[Ts]]), 'typing.Tuple[typing.Unpack[Ts]]')
1440+
self.assertEqual(repr(tuple[*Ts]), 'tuple[typing.Unpack[~Ts]]')
1441+
self.assertEqual(repr(Tuple[Unpack[Ts]]), 'typing.Tuple[typing.Unpack[~Ts]]')
14421442

1443-
self.assertEqual(repr(*tuple[*Ts]), '*tuple[typing.Unpack[Ts]]')
1444-
self.assertEqual(repr(Unpack[Tuple[Unpack[Ts]]]), 'typing.Unpack[typing.Tuple[typing.Unpack[Ts]]]')
1443+
self.assertEqual(repr(*tuple[*Ts]), '*tuple[typing.Unpack[~Ts]]')
1444+
self.assertEqual(repr(Unpack[Tuple[Unpack[Ts]]]), 'typing.Unpack[typing.Tuple[typing.Unpack[~Ts]]]')
14451445

14461446
def test_variadic_class_repr_is_correct(self):
14471447
Ts = TypeVarTuple('Ts')
@@ -1480,61 +1480,61 @@ def test_variadic_class_alias_repr_is_correct(self):
14801480
class A(Generic[Unpack[Ts]]): pass
14811481

14821482
B = A[*Ts]
1483-
self.assertEndsWith(repr(B), 'A[typing.Unpack[Ts]]')
1483+
self.assertEndsWith(repr(B), 'A[typing.Unpack[~Ts]]')
14841484
self.assertEndsWith(repr(B[()]), 'A[()]')
14851485
self.assertEndsWith(repr(B[float]), 'A[float]')
14861486
self.assertEndsWith(repr(B[float, str]), 'A[float, str]')
14871487

14881488
C = A[Unpack[Ts]]
1489-
self.assertEndsWith(repr(C), 'A[typing.Unpack[Ts]]')
1489+
self.assertEndsWith(repr(C), 'A[typing.Unpack[~Ts]]')
14901490
self.assertEndsWith(repr(C[()]), 'A[()]')
14911491
self.assertEndsWith(repr(C[float]), 'A[float]')
14921492
self.assertEndsWith(repr(C[float, str]), 'A[float, str]')
14931493

14941494
D = A[*Ts, int]
1495-
self.assertEndsWith(repr(D), 'A[typing.Unpack[Ts], int]')
1495+
self.assertEndsWith(repr(D), 'A[typing.Unpack[~Ts], int]')
14961496
self.assertEndsWith(repr(D[()]), 'A[int]')
14971497
self.assertEndsWith(repr(D[float]), 'A[float, int]')
14981498
self.assertEndsWith(repr(D[float, str]), 'A[float, str, int]')
14991499

15001500
E = A[Unpack[Ts], int]
1501-
self.assertEndsWith(repr(E), 'A[typing.Unpack[Ts], int]')
1501+
self.assertEndsWith(repr(E), 'A[typing.Unpack[~Ts], int]')
15021502
self.assertEndsWith(repr(E[()]), 'A[int]')
15031503
self.assertEndsWith(repr(E[float]), 'A[float, int]')
15041504
self.assertEndsWith(repr(E[float, str]), 'A[float, str, int]')
15051505

15061506
F = A[int, *Ts]
1507-
self.assertEndsWith(repr(F), 'A[int, typing.Unpack[Ts]]')
1507+
self.assertEndsWith(repr(F), 'A[int, typing.Unpack[~Ts]]')
15081508
self.assertEndsWith(repr(F[()]), 'A[int]')
15091509
self.assertEndsWith(repr(F[float]), 'A[int, float]')
15101510
self.assertEndsWith(repr(F[float, str]), 'A[int, float, str]')
15111511

15121512
G = A[int, Unpack[Ts]]
1513-
self.assertEndsWith(repr(G), 'A[int, typing.Unpack[Ts]]')
1513+
self.assertEndsWith(repr(G), 'A[int, typing.Unpack[~Ts]]')
15141514
self.assertEndsWith(repr(G[()]), 'A[int]')
15151515
self.assertEndsWith(repr(G[float]), 'A[int, float]')
15161516
self.assertEndsWith(repr(G[float, str]), 'A[int, float, str]')
15171517

15181518
H = A[int, *Ts, str]
1519-
self.assertEndsWith(repr(H), 'A[int, typing.Unpack[Ts], str]')
1519+
self.assertEndsWith(repr(H), 'A[int, typing.Unpack[~Ts], str]')
15201520
self.assertEndsWith(repr(H[()]), 'A[int, str]')
15211521
self.assertEndsWith(repr(H[float]), 'A[int, float, str]')
15221522
self.assertEndsWith(repr(H[float, str]), 'A[int, float, str, str]')
15231523

15241524
I = A[int, Unpack[Ts], str]
1525-
self.assertEndsWith(repr(I), 'A[int, typing.Unpack[Ts], str]')
1525+
self.assertEndsWith(repr(I), 'A[int, typing.Unpack[~Ts], str]')
15261526
self.assertEndsWith(repr(I[()]), 'A[int, str]')
15271527
self.assertEndsWith(repr(I[float]), 'A[int, float, str]')
15281528
self.assertEndsWith(repr(I[float, str]), 'A[int, float, str, str]')
15291529

15301530
J = A[*Ts, *tuple[str, ...]]
1531-
self.assertEndsWith(repr(J), 'A[typing.Unpack[Ts], *tuple[str, ...]]')
1531+
self.assertEndsWith(repr(J), 'A[typing.Unpack[~Ts], *tuple[str, ...]]')
15321532
self.assertEndsWith(repr(J[()]), 'A[*tuple[str, ...]]')
15331533
self.assertEndsWith(repr(J[float]), 'A[float, *tuple[str, ...]]')
15341534
self.assertEndsWith(repr(J[float, str]), 'A[float, str, *tuple[str, ...]]')
15351535

15361536
K = A[Unpack[Ts], Unpack[Tuple[str, ...]]]
1537-
self.assertEndsWith(repr(K), 'A[typing.Unpack[Ts], typing.Unpack[typing.Tuple[str, ...]]]')
1537+
self.assertEndsWith(repr(K), 'A[typing.Unpack[~Ts], typing.Unpack[typing.Tuple[str, ...]]]')
15381538
self.assertEndsWith(repr(K[()]), 'A[typing.Unpack[typing.Tuple[str, ...]]]')
15391539
self.assertEndsWith(repr(K[float]), 'A[float, typing.Unpack[typing.Tuple[str, ...]]]')
15401540
self.assertEndsWith(repr(K[float, str]), 'A[float, str, typing.Unpack[typing.Tuple[str, ...]]]')
@@ -1555,9 +1555,9 @@ class G(type(Unpack[Ts])): pass
15551555
with self.assertRaisesRegex(TypeError,
15561556
r'Cannot subclass typing\.Unpack'):
15571557
class H(Unpack): pass
1558-
with self.assertRaisesRegex(TypeError, r'Cannot subclass typing.Unpack\[Ts\]'):
1558+
with self.assertRaisesRegex(TypeError, r'Cannot subclass typing.Unpack\[~Ts\]'):
15591559
class I(*Ts): pass
1560-
with self.assertRaisesRegex(TypeError, r'Cannot subclass typing.Unpack\[Ts\]'):
1560+
with self.assertRaisesRegex(TypeError, r'Cannot subclass typing.Unpack\[~Ts\]'):
15611561
class J(Unpack[Ts]): pass
15621562

15631563
def test_variadic_class_args_are_correct(self):
@@ -5506,13 +5506,13 @@ class TsP(Generic[*Ts, P]):
55065506
MyCallable[[int], bool]: "MyCallable[[int], bool]",
55075507
MyCallable[[int, str], bool]: "MyCallable[[int, str], bool]",
55085508
MyCallable[[int, list[int]], bool]: "MyCallable[[int, list[int]], bool]",
5509-
MyCallable[Concatenate[*Ts, P], T]: "MyCallable[typing.Concatenate[typing.Unpack[Ts], ~P], ~T]",
5509+
MyCallable[Concatenate[*Ts, P], T]: "MyCallable[typing.Concatenate[typing.Unpack[~Ts], ~P], ~T]",
55105510

55115511
DoubleSpec[P2, P, T]: "DoubleSpec[~P2, ~P, ~T]",
55125512
DoubleSpec[[int], [str], bool]: "DoubleSpec[[int], [str], bool]",
55135513
DoubleSpec[[int, int], [str, str], bool]: "DoubleSpec[[int, int], [str, str], bool]",
55145514

5515-
TsP[*Ts, P]: "TsP[typing.Unpack[Ts], ~P]",
5515+
TsP[*Ts, P]: "TsP[typing.Unpack[~Ts], ~P]",
55165516
TsP[int, str, list[int], []]: "TsP[int, str, list[int], []]",
55175517
TsP[int, [str, list[int]]]: "TsP[int, [str, list[int]]]",
55185518

0 commit comments

Comments
 (0)