mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-91621: Fix typing.get_type_hints for collections.abc.Callable (#91656)
This mirrors logic in typing.get_args. The trickiness comes from how we flatten args in collections.abc.Callable, see https://bugs.python.org/issue42195
This commit is contained in:
parent
aff8c4f488
commit
ebb8b512e9
3 changed files with 35 additions and 3 deletions
|
@ -4876,6 +4876,17 @@ class GetTypeHintTests(BaseTestCase):
|
|||
'a': Annotated[Required[int], "a", "b", "c"]
|
||||
})
|
||||
|
||||
def test_get_type_hints_collections_abc_callable(self):
|
||||
# https://github.com/python/cpython/issues/91621
|
||||
P = ParamSpec('P')
|
||||
def f(x: collections.abc.Callable[[int], int]): ...
|
||||
def g(x: collections.abc.Callable[..., int]): ...
|
||||
def h(x: collections.abc.Callable[P, int]): ...
|
||||
|
||||
self.assertEqual(get_type_hints(f), {'x': collections.abc.Callable[[int], int]})
|
||||
self.assertEqual(get_type_hints(g), {'x': collections.abc.Callable[..., int]})
|
||||
self.assertEqual(get_type_hints(h), {'x': collections.abc.Callable[P, int]})
|
||||
|
||||
|
||||
class GetUtilitiesTestCase(TestCase):
|
||||
def test_get_origin(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue