@@ -1131,10 +1131,6 @@ class P(PR[int, T], Protocol[T]):
1131
1131
PR [int ]
1132
1132
with self .assertRaises (TypeError ):
1133
1133
P [int , str ]
1134
- with self .assertRaises (TypeError ):
1135
- PR [int , 1 ]
1136
- with self .assertRaises (TypeError ):
1137
- PR [int , ClassVar ]
1138
1134
1139
1135
class C (PR [int , T ]): pass
1140
1136
@@ -1156,8 +1152,6 @@ class P(PR[int, str], Protocol):
1156
1152
self .assertIsSubclass (P , PR )
1157
1153
with self .assertRaises (TypeError ):
1158
1154
PR [int ]
1159
- with self .assertRaises (TypeError ):
1160
- PR [int , 1 ]
1161
1155
1162
1156
class P1 (Protocol , Generic [T ]):
1163
1157
def bar (self , x : T ) -> str : ...
@@ -1176,8 +1170,6 @@ def bar(self, x: str) -> str:
1176
1170
return x
1177
1171
1178
1172
self .assertIsInstance (Test (), PSub )
1179
- with self .assertRaises (TypeError ):
1180
- PR [int , ClassVar ]
1181
1173
1182
1174
def test_init_called (self ):
1183
1175
T = TypeVar ('T' )
@@ -4346,25 +4338,30 @@ class X(Generic[T, P]):
4346
4338
self .assertEqual (G2 .__parameters__ , (P_2 ,))
4347
4339
4348
4340
# currently raises TypeError for _type_check
4349
- # G3 = X[int, [int, bool]]
4350
- # self.assertEqual(G3.__args__, (int, [int, bool]))
4351
- # self.assertEqual(G3.__parameters__, ())
4352
-
4353
- # G4 = X[int, ...]
4354
- # self.assertEqual(G4.__args__, (int, type(Ellipsis)))
4355
- # self.assertEqual(G4.__parameters__, ())
4356
- #
4357
- # class Z(Generic[P]):
4358
- # f: Callable[P, int]
4359
-
4360
- # These are valid
4361
- # currently raises TypeError for _type_check
4362
- # G5 = Z[[int, str, bool]]
4341
+ G3 = X [int , [int , bool ]]
4342
+ self .assertEqual (G3 .__args__ , (int , (int , bool )))
4343
+ self .assertEqual (G3 .__parameters__ , ())
4344
+
4345
+ G4 = X [int , ...]
4346
+ self .assertEqual (G4 .__args__ , (int , Ellipsis ))
4347
+ self .assertEqual (G4 .__parameters__ , ())
4348
+
4349
+ class Z (Generic [P ]):
4350
+ f : Callable [P , int ]
4351
+
4352
+ G5 = Z [[int , str , bool ]]
4353
+ self .assertEqual (G5 .__args__ , ((int , str , bool ),))
4354
+ self .assertEqual (G5 .__parameters__ , ())
4355
+
4356
+ G6 = Z [int , str , bool ]
4357
+ self .assertEqual (G6 .__args__ , ((int , str , bool ),))
4358
+ self .assertEqual (G6 .__parameters__ , ())
4363
4359
4364
- # currently raises TypeError for too many parameters (not enough TypeVars)
4365
- # G6 = Z[int, str, bool]
4366
- # self.assertEqual(G6.__args__, (int, str, bool))
4367
- # self.assertEqual(G6.__parameters__, ())
4360
+ # G5 and G6 should be equivalent according to the PEP
4361
+ self .assertEqual (G5 .__args__ , G6 .__args__ )
4362
+ self .assertEqual (G5 .__origin__ , G6 .__origin__ )
4363
+ self .assertEqual (G5 .__parameters__ , G6 .__parameters__ )
4364
+ self .assertEqual (G5 , G6 )
4368
4365
4369
4366
4370
4367
class ConcatenateTests (BaseTestCase ):
0 commit comments