Skip to content

Commit 1dd01db

Browse files
committed
Reset lambda argument types in empty context
1 parent c79069b commit 1dd01db

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

mypy/checkexpr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5591,6 +5591,10 @@ def visit_lambda_expr(self, e: LambdaExpr) -> Type:
55915591
self.chk.binder.frame_context(can_skip=True, fall_through=0),
55925592
self.chk.scope.push_function(e),
55935593
):
5594+
# If in empty context, reset argument types (from previous passes),
5595+
# in the other branch argument types are set by check_func_def().
5596+
for arg in e.arguments:
5597+
arg.variable.type = None
55945598
# Lambdas can have more than one element in body,
55955599
# when we add "fictional" AssignmentStatement nodes, like in:
55965600
# `lambda (a, b): a`

test-data/unit/check-functions.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,6 +2562,26 @@ reveal_type(f)
25622562
[out]
25632563
main:2: note: Revealed type is "def () -> builtins.int"
25642564

2565+
[case testDeferredLambdaInOverload]
2566+
from typing import Any, Callable, overload
2567+
2568+
@overload
2569+
def option(*, callback: Callable[[str], object] = ...) -> Any: ...
2570+
@overload
2571+
def option(*, callback: Callable[[int], object] = ...) -> Any: ...
2572+
def option(**kwargs: object) -> None: pass
2573+
2574+
def test() -> None:
2575+
option(callback=lambda x: [y for y in x]) # OK
2576+
x = C().x
2577+
2578+
class C:
2579+
def __init__(self) -> None:
2580+
self.x = defer()
2581+
2582+
def defer() -> int: ...
2583+
[builtins fixtures/primitives.pyi]
2584+
25652585
[case testRevealLocalsFunction]
25662586
a = 1.0
25672587

0 commit comments

Comments
 (0)