Skip to content

Commit

Permalink
Merge pull request python#150 from vlasovskikh/fix-ellipsis-in-callable
Browse files Browse the repository at this point in the history
Don't iterate over ellipsis in Callable when evaluating types. Fix python#149
  • Loading branch information
gvanrossum committed Aug 2, 2015
2 parents 54c0641 + f8a86f0 commit 10da00d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions prototyping/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion prototyping/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 10da00d

Please sign in to comment.