diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index cabe3ecf41c57..12be68ffb2b43 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -1238,7 +1238,9 @@ def infer_overload_return_type(self, for typ in plausible_targets: overload_messages = self.msg.clean_copy() prev_messages = self.msg + assert self.msg is self.chk.msg self.msg = overload_messages + self.chk.msg = overload_messages try: # Passing `overload_messages` as the `arg_messages` parameter doesn't # seem to reliably catch all possible errors. @@ -1253,6 +1255,7 @@ def infer_overload_return_type(self, callable_name=callable_name, object_type=object_type) finally: + self.chk.msg = prev_messages self.msg = prev_messages is_match = not overload_messages.is_errors() diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 3208036afe365..03453cc74f4d6 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -2620,3 +2620,32 @@ class FakeAttribute(Generic[T]): @overload def dummy(self, instance: T, owner: Type[T]) -> int: ... def dummy(self, instance: Optional[T], owner: Type[T]) -> Union['FakeAttribute[T]', int]: ... + +[case testOverloadLambdaUnpackingInference] +# flags: --py2 +from typing import Callable, TypeVar, overload + +T = TypeVar('T') +S = TypeVar('S') + +@overload +def foo(func, item): + # type: (Callable[[T], S], T) -> S + pass + +@overload +def foo(): + # type: () -> None + pass + +def foo(*args): + pass + +def add_proxy(x, y): + # type: (int, str) -> str + pass + +# The lambda definition is a syntax error in Python 3 +tup = (1, '2') +reveal_type(foo(lambda (x, y): add_proxy(x, y), tup)) # E: Revealed type is 'builtins.str*' +[builtins fixtures/primitives.pyi]