diff --git a/prototyping/test_typing.py b/prototyping/test_typing.py index 2bb21edc1889..509273629d9f 100644 --- a/prototyping/test_typing.py +++ b/prototyping/test_typing.py @@ -459,6 +459,14 @@ def test_repr(self): ctv = Callable[..., str] self.assertEqual(repr(ctv), 'typing.Callable[..., str]') + def test_callable_with_ellipsis(self): + + def foo(a: Callable[..., T]): + pass + + self.assertEqual(get_type_hints(foo, globals(), locals()), + {'a': Callable[..., T]}) + XK = TypeVar('XK', str, bytes) XV = TypeVar('XV') @@ -801,6 +809,14 @@ def foo(a: Callable[['T'], 'T']): self.assertEqual(get_type_hints(foo, globals(), locals()), {'a': Callable[[T], T]}) + def test_callable_with_ellipsis_forward(self): + + def foo(a: 'Callable[..., T]'): + pass + + self.assertEqual(get_type_hints(foo, globals(), locals()), + {'a': Callable[..., T]}) + def test_syntax_error(self): with self.assertRaises(SyntaxError): diff --git a/prototyping/typing.py b/prototyping/typing.py index bc6fcdd03d7c..08ad8c9c422a 100644 --- a/prototyping/typing.py +++ b/prototyping/typing.py @@ -767,7 +767,10 @@ def _has_type_var(self): def _eval_type(self, globalns, localns): if self.__args__ is None and self.__result__ is None: return self - args = [_eval_type(t, globalns, localns) for t in self.__args__] + if self.__args__ is Ellipsis: + args = self.__args__ + else: + args = [_eval_type(t, globalns, localns) for t in self.__args__] result = _eval_type(self.__result__, globalns, localns) if args == self.__args__ and result == self.__result__: return self