diff --git a/mypy/reachability.py b/mypy/reachability.py index 132c269e96af..37c7a9715600 100644 --- a/mypy/reachability.py +++ b/mypy/reachability.py @@ -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) diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index 466b46686831..e9fbf4eb1219 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -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