Skip to content
Merged
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
5 changes: 1 addition & 4 deletions mypy/reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ def infer_reachability_of_match_statement(s: MatchStmt, options: Options) -> Non
):
# The case is considered always false, so we skip the case body.
mark_block_unreachable(s.bodies[i])
elif pattern_value in (ALWAYS_FALSE, MYPY_TRUE) and guard_value in (
ALWAYS_TRUE,
MYPY_TRUE,
):
elif pattern_value in (ALWAYS_TRUE, MYPY_TRUE) and guard_value in (ALWAYS_TRUE, MYPY_TRUE):
for body in s.bodies[i + 1 :]:
mark_block_unreachable(body)

Expand Down
20 changes: 19 additions & 1 deletion test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -2899,9 +2899,27 @@ def f4(e: int | str | bytes) -> int:
return 0
reveal_type(e) # N: Revealed type is "builtins.int | builtins.bytes"
return 0

[builtins fixtures/primitives.pyi]

[case testMatchGuardAlwaysTrueAlwaysFalse]
# flags: --warn-unreachable --always-true TRUEFLAG --always-false FALSEFLAG
TRUEFLAG = False
FALSEFLAG = True

def true_flag(e: int) -> None:
match e:
case _ if TRUEFLAG:
pass
case 0:
# No error
1 + "asdf"

def false_flag(e: int) -> None:
match e:
case _ if FALSEFLAG:
# No error
1 + "asdf"

[case testMatchSequencePatternVariadicTupleNotTooShort]
from typing import Tuple
from typing_extensions import Unpack
Expand Down