bpo-42740: Fix get_args for PEP 585 collections.abc.Callable (GH-23963)
PR 1/2. Needs backport to 3.9.
This commit is contained in:
parent
a9621bb301
commit
4140f10a16
|
@ -3048,6 +3048,11 @@ class GetUtilitiesTestCase(TestCase):
|
||||||
self.assertEqual(get_args(Callable), ())
|
self.assertEqual(get_args(Callable), ())
|
||||||
self.assertEqual(get_args(list[int]), (int,))
|
self.assertEqual(get_args(list[int]), (int,))
|
||||||
self.assertEqual(get_args(list), ())
|
self.assertEqual(get_args(list), ())
|
||||||
|
self.assertEqual(get_args(collections.abc.Callable[[int], str]), ([int], str))
|
||||||
|
self.assertEqual(get_args(collections.abc.Callable[..., str]), (..., str))
|
||||||
|
self.assertEqual(get_args(collections.abc.Callable[[], str]), ([], str))
|
||||||
|
self.assertEqual(get_args(collections.abc.Callable[[int], str]),
|
||||||
|
get_args(Callable[[int], str]))
|
||||||
|
|
||||||
|
|
||||||
class CollectionsAbcTests(BaseTestCase):
|
class CollectionsAbcTests(BaseTestCase):
|
||||||
|
|
|
@ -1684,13 +1684,11 @@ def get_args(tp):
|
||||||
"""
|
"""
|
||||||
if isinstance(tp, _AnnotatedAlias):
|
if isinstance(tp, _AnnotatedAlias):
|
||||||
return (tp.__origin__,) + tp.__metadata__
|
return (tp.__origin__,) + tp.__metadata__
|
||||||
if isinstance(tp, _GenericAlias):
|
if isinstance(tp, (_GenericAlias, GenericAlias)):
|
||||||
res = tp.__args__
|
res = tp.__args__
|
||||||
if tp.__origin__ is collections.abc.Callable and res[0] is not Ellipsis:
|
if tp.__origin__ is collections.abc.Callable and res[0] is not Ellipsis:
|
||||||
res = (list(res[:-1]), res[-1])
|
res = (list(res[:-1]), res[-1])
|
||||||
return res
|
return res
|
||||||
if isinstance(tp, GenericAlias):
|
|
||||||
return tp.__args__
|
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue