diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_types.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 0816f5a..2d0e33f 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -711,6 +711,8 @@ class TypesTests(unittest.TestCase): TV = typing.TypeVar('T') assert TV | str == typing.Union[TV, str] assert str | TV == typing.Union[str, TV] + self.assertIs((int | TV)[int], int) + self.assertIs((TV | int)[int], int) def test_union_args(self): def check(arg, expected): @@ -742,6 +744,17 @@ class TypesTests(unittest.TestCase): check(x | None, (x, type(None))) check(None | x, (type(None), x)) + def test_union_parameter_chaining(self): + T = typing.TypeVar("T") + S = typing.TypeVar("S") + + self.assertEqual((float | list[T])[int], float | list[int]) + self.assertEqual(list[int | list[T]].__parameters__, (T,)) + self.assertEqual(list[int | list[T]][str], list[int | list[str]]) + self.assertEqual((list[T] | list[S]).__parameters__, (T, S)) + self.assertEqual((list[T] | list[S])[int, T], list[int] | list[T]) + self.assertEqual((list[T] | list[S])[int, int], list[int]) + def test_or_type_operator_with_forward(self): T = typing.TypeVar('T') ForwardAfter = T | 'Forward' |