Skip to content

Commit d4e72a5

Browse files
committed
A few more tests
1 parent f412f49 commit d4e72a5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Lib/test/test_type_aliases.py

+24
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,27 @@ def test_errors(self):
178178
TypeAliasType("TA", list, ())
179179
with self.assertRaises(TypeError):
180180
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

Comments
 (0)