Skip to content

Commit

Permalink
Fix regression in container check logic (#8232)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michael0x2a authored and ilevkivskyi committed Jan 3, 2020
1 parent 9101707 commit cdd91ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/checker.py
Expand Up @@ -3915,7 +3915,7 @@ def find_isinstance_check_helper(self, node: Expression) -> Tuple[TypeMap, TypeM

# We only try and narrow away 'None' for now
if not is_optional(item_type):
pass
continue

collection_item_type = get_proper_type(builtin_item_type(collection_type))
if collection_item_type is None or is_optional(collection_item_type):
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-optional.test
Expand Up @@ -550,6 +550,15 @@ else:
reveal_type(b) # N: Revealed type is 'Union[__main__.A, None]'
[builtins fixtures/ops.pyi]

[case testInferInWithErasedTypes]
from typing import TypeVar, Callable

T = TypeVar('T')
def foo(f: Callable[[T], bool], it: T) -> None: ...

foo(lambda x: x in [1, 2] and bool(), 3)
[builtins fixtures/list.pyi]

[case testWarnNoReturnWorksWithStrictOptional]
# flags: --warn-no-return
def f() -> None:
Expand Down

0 comments on commit cdd91ba

Please sign in to comment.