@@ -1075,52 +1075,43 @@ async def coroutine[B]():
10751075
10761076class TypeParamsTypeVarTupleTest (unittest .TestCase ):
10771077 def test_typevartuple_01 (self ):
1078- code = """def func1[*A: str](): pass"""
1079- check_syntax_error (self , code , "cannot use bound with TypeVarTuple" )
1080- code = """def func1[*A: (int, str)](): pass"""
1081- check_syntax_error (self , code , "cannot use constraints with TypeVarTuple" )
1082- code = """class X[*A: str]: pass"""
1083- check_syntax_error (self , code , "cannot use bound with TypeVarTuple" )
1084- code = """class X[*A: (int, str)]: pass"""
1085- check_syntax_error (self , code , "cannot use constraints with TypeVarTuple" )
1086- code = """type X[*A: str] = int"""
1087- check_syntax_error (self , code , "cannot use bound with TypeVarTuple" )
1088- code = """type X[*A: (int, str)] = int"""
1089- check_syntax_error (self , code , "cannot use constraints with TypeVarTuple" )
1090-
1091- def test_typevartuple_02 (self ):
1092- def func1 [* A ]():
1093- return A
1094-
1095- a = func1 ()
1078+ def func1 [* A : str , * B : str | int ]():
1079+ return A , B
1080+
1081+ a , b = func1 ()
1082+
10961083 self .assertIsInstance (a , TypeVarTuple )
1084+ self .assertEqual (a .__bound__ , str )
1085+ self .assertTrue (a .__infer_variance__ )
1086+ self .assertFalse (a .__covariant__ )
1087+ self .assertFalse (a .__contravariant__ )
1088+
1089+ self .assertIsInstance (b , TypeVarTuple )
1090+ self .assertEqual (b .__bound__ , str | int )
1091+ self .assertTrue (b .__infer_variance__ )
1092+ self .assertFalse (b .__covariant__ )
1093+ self .assertFalse (b .__contravariant__ )
10971094
10981095
10991096class TypeParamsTypeVarParamSpecTest (unittest .TestCase ):
11001097 def test_paramspec_01 (self ):
1101- code = """def func1[**A: str](): pass"""
1102- check_syntax_error (self , code , "cannot use bound with ParamSpec" )
1103- code = """def func1[**A: (int, str)](): pass"""
1104- check_syntax_error (self , code , "cannot use constraints with ParamSpec" )
1105- code = """class X[**A: str]: pass"""
1106- check_syntax_error (self , code , "cannot use bound with ParamSpec" )
1107- code = """class X[**A: (int, str)]: pass"""
1108- check_syntax_error (self , code , "cannot use constraints with ParamSpec" )
1109- code = """type X[**A: str] = int"""
1110- check_syntax_error (self , code , "cannot use bound with ParamSpec" )
1111- code = """type X[**A: (int, str)] = int"""
1112- check_syntax_error (self , code , "cannot use constraints with ParamSpec" )
1113-
1114- def test_paramspec_02 (self ):
1115- def func1 [** A ]():
1116- return A
1117-
1118- a = func1 ()
1098+ def func1 [** A : [str ], ** B : [str | int ]]():
1099+ return A , B
1100+
1101+ a , b = func1 ()
1102+
11191103 self .assertIsInstance (a , ParamSpec )
1104+ self .assertEqual (a .__bound__ , [str ])
11201105 self .assertTrue (a .__infer_variance__ )
11211106 self .assertFalse (a .__covariant__ )
11221107 self .assertFalse (a .__contravariant__ )
11231108
1109+ self .assertIsInstance (b , ParamSpec )
1110+ self .assertEqual (b .__bound__ , [str | int ])
1111+ self .assertTrue (b .__infer_variance__ )
1112+ self .assertFalse (b .__covariant__ )
1113+ self .assertFalse (b .__contravariant__ )
1114+
11241115
11251116class TypeParamsTypeParamsDunder (unittest .TestCase ):
11261117 def test_typeparams_dunder_class_01 (self ):
@@ -1264,7 +1255,7 @@ class NewStyle[T]:
12641255 P ,
12651256 P .args ,
12661257 P .kwargs ,
1267- TypeVarTuple ('Ts' ),
1258+ TypeVarTuple ('Ts' , bound = int ),
12681259 OldStyle ,
12691260 OldStyle [int ],
12701261 OldStyle (),
@@ -1422,22 +1413,26 @@ class TestEvaluateFunctions(unittest.TestCase):
14221413 def test_general (self ):
14231414 type Alias = int
14241415 Alias2 = TypeAliasType ("Alias2" , int )
1425- def f [T : int = int , ** P = int , * Ts = int ](): pass
1426- T , P , Ts = f .__type_params__
1416+ def f [T : int = int , * Ts : int = int , ** P : [ int ] = int ](): pass
1417+ T , Ts , P = f .__type_params__
14271418 T2 = TypeVar ("T2" , bound = int , default = int )
1428- P2 = ParamSpec ( "P2" , default = int )
1429- Ts2 = TypeVarTuple ( "Ts2" , default = int )
1419+ Ts2 = TypeVarTuple ( "Ts2" , bound = int , default = int )
1420+ P2 = ParamSpec ( "P2" , bound = [ int ] , default = int )
14301421 cases = [
14311422 Alias .evaluate_value ,
14321423 Alias2 .evaluate_value ,
14331424 T .evaluate_bound ,
14341425 T .evaluate_default ,
1435- P . evaluate_default ,
1426+ Ts . evaluate_bound ,
14361427 Ts .evaluate_default ,
1428+ P .evaluate_bound ,
1429+ P .evaluate_default ,
14371430 T2 .evaluate_bound ,
14381431 T2 .evaluate_default ,
1439- P2 . evaluate_default ,
1432+ Ts2 . evaluate_bound ,
14401433 Ts2 .evaluate_default ,
1434+ P2 .evaluate_bound ,
1435+ P2 .evaluate_default ,
14411436 ]
14421437 for case in cases :
14431438 with self .subTest (case = case ):
0 commit comments