@@ -178,3 +178,27 @@ def test_errors(self):
178
178
TypeAliasType ("TA" , list , ())
179
179
with self .assertRaises (TypeError ):
180
180
TypeAliasType ("TA" , list , type_params = 42 )
181
+
182
+
183
+ class TypeAliasTypeTest (unittest .TestCase ):
184
+ def test_immutable (self ):
185
+ with self .assertRaises (TypeError ):
186
+ TypeAliasType .whatever = "not allowed"
187
+
188
+ def test_no_subclassing (self ):
189
+ with self .assertRaisesRegex (TypeError , "not an acceptable base type" ):
190
+ class MyAlias (TypeAliasType ):
191
+ pass
192
+
193
+ def test_union (self ):
194
+ type Alias1 = int
195
+ type Alias2 = str
196
+ union = Alias1 | Alias2
197
+ self .assertIsInstance (union , types .UnionType )
198
+ self .assertEqual (get_args (union ), (Alias1 , Alias2 ))
199
+ union2 = Alias1 | list [float ]
200
+ self .assertIsInstance (union2 , types .UnionType )
201
+ self .assertEqual (get_args (union2 ), (Alias1 , list [float ]))
202
+ union3 = list [range ] | Alias1
203
+ self .assertIsInstance (union3 , types .UnionType )
204
+ self .assertEqual (get_args (union3 ), (list [range ], Alias1 ))
0 commit comments