Skip to content

Commit 006721a

Browse files
author
Guido van Rossum
committed
Avoid crash on lamba (a, b): a with context. Fix #1421
1 parent 08ad739 commit 006721a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

mypy/checkexpr.py

Lines changed: 2 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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)