Skip to content

Commit

Permalink
A few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed May 15, 2023
1 parent f412f49 commit d4e72a5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Lib/test/test_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,27 @@ def test_errors(self):
TypeAliasType("TA", list, ())
with self.assertRaises(TypeError):
TypeAliasType("TA", list, type_params=42)


class TypeAliasTypeTest(unittest.TestCase):
def test_immutable(self):
with self.assertRaises(TypeError):
TypeAliasType.whatever = "not allowed"

def test_no_subclassing(self):
with self.assertRaisesRegex(TypeError, "not an acceptable base type"):
class MyAlias(TypeAliasType):
pass

def test_union(self):
type Alias1 = int
type Alias2 = str
union = Alias1 | Alias2
self.assertIsInstance(union, types.UnionType)
self.assertEqual(get_args(union), (Alias1, Alias2))
union2 = Alias1 | list[float]
self.assertIsInstance(union2, types.UnionType)
self.assertEqual(get_args(union2), (Alias1, list[float]))
union3 = list[range] | Alias1
self.assertIsInstance(union3, types.UnionType)
self.assertEqual(get_args(union3), (list[range], Alias1))

0 comments on commit d4e72a5

Please sign in to comment.