From 535bc7fa943abc5b9baada203945eefe674ff4d5 Mon Sep 17 00:00:00 2001 From: Sudhakar Date: Thu, 19 Nov 2026 08:45:18 +0530 Subject: [PATCH] fix: suppress spurious unreachable errors in sequence pattern union matching When matching sequence patterns against union types, avoid reporting impossible-intersection diagnostics for individual non-matching union alternatives. Fixes #22150 --- mypy/checkpattern.py | 3 ++- test-data/unit/check-python310.test | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mypy/checkpattern.py b/mypy/checkpattern.py index 0e4786910e116..f0854145fea50 100644 --- a/mypy/checkpattern.py +++ b/mypy/checkpattern.py @@ -264,7 +264,8 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType: star_expr = None for t in current_type.items: - match_type, rest_type, captures = self.accept(o, t) + with self.msg.filter_errors(): + match_type, rest_type, captures = self.accept(o, t) match_types.append(match_type) rest_types.append(rest_type) if not is_uninhabited(match_type): diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index 33b952f48f49d..362b28f036540 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -4019,3 +4019,15 @@ def enum_then_dummy_class(arg: DummyClass | Literal[MyEnum.RELEVANT]): case _: pass # E: Statement is unreachable [builtins fixtures/tuple.pyi] + +[case testMatchSequencePatternUnionTupleNoUnreachable] +# flags: --warn-unreachable +def f(value: tuple[None, int] | tuple[int, None] | tuple[int, int]) -> None: + match value: + case (None, int(y)): + pass + case (int(x), None): + pass + case (int(x), int(y)): + pass +[builtins fixtures/tuple.pyi]