diff --git a/mypy/checker.py b/mypy/checker.py index ae829d1157c1..5046d9431b4f 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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): diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index 9c40d550699e..15698e99ddf5 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -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: