Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on partial type inference within a lambda #14087

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7031,6 +7031,9 @@ def is_valid_inferred_type(typ: Type, is_lvalue_final: bool = False) -> bool:
return is_lvalue_final
elif isinstance(proper_type, UninhabitedType):
return False
elif mypy.checkexpr.has_erased_component(typ):
# This can happen inside a lambda.
return False
return not typ.accept(NothingSeeker())


Expand Down
26 changes: 26 additions & 0 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -6286,3 +6286,29 @@ class C: ...
[out]
[out2]
[out3]

[case testNoCrashOnPartialLambdaInference]
import m
[file m.py]
from typing import TypeVar, Callable

V = TypeVar("V")
def apply(val: V, func: Callable[[V], None]) -> None:
return func(val)

xs = []
apply(0, lambda a: xs.append(a))
[file m.py.2]
from typing import TypeVar, Callable

V = TypeVar("V")
def apply(val: V, func: Callable[[V], None]) -> None:
return func(val)

xs = []
apply(0, lambda a: xs.append(a))
reveal_type(xs)
[builtins fixtures/list.pyi]
[out]
[out2]
tmp/m.py:9: note: Revealed type is "builtins.list[builtins.int]"