bpo-42740: Support PEP 604, 612 for typing.py get_args and get_origin (GH-23942)

This commit is contained in:
Ken Jin 2020-12-29 10:26:19 +08:00 committed by GitHub
parent a6d63a20df
commit efb1f0918f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -3021,6 +3021,7 @@ class GetUtilitiesTestCase(TestCase):
self.assertIs(get_origin(Callable), collections.abc.Callable)
self.assertIs(get_origin(list[int]), list)
self.assertIs(get_origin(list), None)
self.assertIs(get_origin(list | str), types.Union)
def test_get_args(self):
T = TypeVar('T')
@ -3053,6 +3054,11 @@ class GetUtilitiesTestCase(TestCase):
self.assertEqual(get_args(collections.abc.Callable[[], str]), ([], str))
self.assertEqual(get_args(collections.abc.Callable[[int], str]),
get_args(Callable[[int], str]))
P = ParamSpec('P')
self.assertEqual(get_args(Callable[P, int]), (P, int))
self.assertEqual(get_args(Callable[Concatenate[int, P], int]),
(Concatenate[int, P], int))
self.assertEqual(get_args(list | str), (list, str))
class CollectionsAbcTests(BaseTestCase):