8000 More test cases, remove redundant comment · python/cpython@b36b7af · GitHub
[go: up one dir, main page]

Skip to content

Commit b36b7af

Browse files
committed
More test cases, remove redundant comment
1 parent 93a4552 commit b36b7af

File tree

2 files changed

+24
-3
lines changed

Lib/test/test_type_aliases.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import types
33
import unittest
44

5-
from typing import TypeAliasType
5+
from typing import Callable, TypeAliasType
66

77
class TypeParamsInvalidTest(unittest.TestCase):
88
def test_name_collision_01(self):
@@ -90,13 +90,34 @@ def outer[A]():
9090
b = o.__parameters__[0]
9191
self.assertEqual(o.__type_params__, (b,))
9292

93+
def more_generic[T, *Ts, **P]():
94+
type TA[T2, *Ts2, **P2] = tuple[Callable[P, tuple[T, *Ts]], Callable[P2, tuple[T2, *Ts2]]]
95+
return TA
96+
97+
alias = more_generic()
98+
self.assertIsInstance(alias, TypeAliasType)
99+
T2, Ts2, P2 = alias.__type_params__
100+
self.assertEqual(alias.__parameters__, (T2, *Ts2, P2))
101+
T, Ts, P = more_generic.__type_params__
102+
self.assertEqual(alias.__value__, tuple[Callable[P, tuple[T, *Ts]], Callable[P2, tuple[T2, *Ts2]]])
103+
93104
def test_subscripting(self):
94105
type NonGeneric = int
95106
type Generic[A] = dict[A, A]
107+
type VeryGeneric[T, *Ts, **P] = Callable[P, tuple[T, *Ts]]
96108

97109
with self.assertRaises(TypeError):
98110
NonGeneric[int]
99-
self.assertIsInstance(Generic[int], types.GenericAlias)
111+
112+
specialized = Generic[int]
113+
self.assertIsInstance(specialized, types.GenericAlias)
114+
self.assertIs(specialized.__origin__, Generic)
115+
self.assertEqual(specialized.__args__, (int,))
116+
117+
specialized2 = VeryGeneric[int, str, float, [bool, range]]
118+
self.assertIsInstance(specialized2, types.GenericAlias)
119+
self.assertIs(specialized2.__origin__, VeryGeneric)
120+
self.assertEqual(specialized2.__args__, (int, str, float, [bool, range]))
100121

101122
def test_repr(self):
102123
type Simple = int

Lib/test/test_type_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def test_nonlocal(self):
257257
def outer2[T]():
258258
259259
def inner1():
260-
nonlocal T # Syntax error: nonlocal binding not allowed for type parameter
260+
nonlocal T
261261
""")
262262
with self.assertRaisesRegex(SyntaxError, "nonlocal binding not allowed for type parameter 'T'"):
263263
exec(code, {})

0 commit comments

Comments
 (0)
0