diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 096d88a54213..658c9be0a9ca 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -1267,6 +1267,8 @@ def visit_func_expr(self, e: FuncExpr) -> Type: else: # Type context available. self.chk.check_func_item(e, type_override=inferred_type) + if e.expr() not in self.chk.type_map: + self.accept(e.expr()) ret_type = self.chk.type_map[e.expr()] return replace_callable_return_type(inferred_type, ret_type) diff --git a/mypy/test/data/check-python2.test b/mypy/test/data/check-python2.test index cf6f960bd175..8ce9f9597dcd 100644 --- a/mypy/test/data/check-python2.test +++ b/mypy/test/data/check-python2.test @@ -193,3 +193,11 @@ def f((x,)): return x def g((x)): return x f(0) + g(0) [out] + +[case testLambdaAsSortKeyForTuplePython2] +from typing import Any, Tuple, Callable +def bar(key: Callable[[Tuple[int, int]], int]) -> int: + pass +def foo() -> int: + return bar(key=lambda (a, b): a) +[out]