Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7072,6 +7072,8 @@ def refine_away_none_in_comparison(
non_optional_types = []
for i in chain_indices:
typ = operand_types[i]
if isinstance(get_proper_type(typ), AnyType):
continue
if not is_overlapping_none(typ):
non_optional_types.append(typ)

Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -1650,3 +1650,10 @@ def x() -> None:
main:4: error: Statement is unreachable
if 5:
^~~~~

[case testNoFalseUnreachableWithAnyEqualityNarrowing]
# flags: --warn-unreachable
from typing import Any, Optional
def main(contents: Any, commit: Optional[str]) -> None:
if contents.get("commit") == commit:
reveal_type(commit) # N: Revealed type is "builtins.str | None"