diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-07-17 19:14:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-17 19:14:57 (GMT) |
commit | 2d055ce13250a4074f66a945381a149a3cf8c46f (patch) | |
tree | 41260fe1f80398f1bfd84517755ac2480a4d409d /Lib | |
parent | e22e8641dd277478b8df7a9fe792ea551adc6932 (diff) | |
download | cpython-2d055ce13250a4074f66a945381a149a3cf8c46f.zip cpython-2d055ce13250a4074f66a945381a149a3cf8c46f.tar.gz cpython-2d055ce13250a4074f66a945381a149a3cf8c46f.tar.bz2 |
[3.10] bpo-44490: Add __parameters__ and __getitem__ to types.Union (GH-26980) (GH-27207)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>.
(cherry picked from commit c45fa1a5d9b419cf13ad4b5a7cb453956495b83e)
Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
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' |