Skip to content

Commit eefab5b

Browse files
committed
Avoid crash on lamba (a, b): a with context. Fix #1421 (#1452)
1 parent fa70fc5 commit eefab5b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

mypy/checkexpr.py

+2
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,8 @@ def visit_func_expr(self, e: FuncExpr) -> Type:
12671267
else:
12681268
# Type context available.
12691269
self.chk.check_func_item(e, type_override=inferred_type)
1270+
if e.expr() not in self.chk.type_map:
1271+
self.accept(e.expr())
12701272
ret_type = self.chk.type_map[e.expr()]
12711273
return replace_callable_return_type(inferred_type, ret_type)
12721274

mypy/test/data/check-python2.test

+8
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,11 @@ def f((x,)): return x
193193
def g((x)): return x
194194
f(0) + g(0)
195195
[out]
196+
197+
[case testLambdaAsSortKeyForTuplePython2]
198+
from typing import Any, Tuple, Callable
199+
def bar(key: Callable[[Tuple[int, int]], int]) -> int:
200+
pass
201+
def foo() -> int:
202+
return bar(key=lambda (a, b): a)
203+
[out]

0 commit comments

Comments
 (0)