Skip to content

Commit cdd91ba

Browse files
Michael0x2ailevkivskyi
authored andcommitted
Fix regression in container check logic (#8232)
This PR fixes the crash reported in #8230, by replacing the 'pass' with the 'continue', as suggested. However, it does *not* fix the underlying root cause -- I don't think I actually understand the relevant pieces of code enough to feel confident volunteering a fix. So, I settled for just fixing the regression. Basically, it seems this bug is due to how we try inferring the type of the lambda in multiple passes to resolve the types. We pencil in an ErasedType during the first pass -- and then subsequently crash when attempting to type check the body during that pass. I'll leave more details about this in the linked issue.
1 parent 9101707 commit cdd91ba

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mypy/checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,7 @@ def find_isinstance_check_helper(self, node: Expression) -> Tuple[TypeMap, TypeM
39153915

39163916
# We only try and narrow away 'None' for now
39173917
if not is_optional(item_type):
3918-
pass
3918+
continue
39193919

39203920
collection_item_type = get_proper_type(builtin_item_type(collection_type))
39213921
if collection_item_type is None or is_optional(collection_item_type):

test-data/unit/check-optional.test

+9
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ else:
550550
reveal_type(b) # N: Revealed type is 'Union[__main__.A, None]'
551551
[builtins fixtures/ops.pyi]
552552

553+
[case testInferInWithErasedTypes]
554+
from typing import TypeVar, Callable
555+
556+
T = TypeVar('T')
557+
def foo(f: Callable[[T], bool], it: T) -> None: ...
558+
559+
foo(lambda x: x in [1, 2] and bool(), 3)
560+
[builtins fixtures/list.pyi]
561+
553562
[case testWarnNoReturnWorksWithStrictOptional]
554563
# flags: --warn-no-return
555564
def f() -> None:

0 commit comments

Comments
 (0)