Skip to content
Closed
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/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
for p, t in zip(o.patterns, contracted_inner_types):
pattern_type = self.accept(p, t)
typ, rest, type_map = pattern_type
if is_uninhabited(typ) and not isinstance(p, StarredPattern):
return self.early_non_match()
contracted_new_inner_types.append(typ)
contracted_rest_inner_types.append(rest)
self.update_type_map(captures, type_map)
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ match m:
reveal_type(m) # N: Revealed type is "tuple[Literal[1], Literal['str']]"
[builtins fixtures/list.pyi]

[case testMatchSequencePatternTupleUnionStopsAfterUnmatchedItem]
# flags: --strict-equality --warn-unreachable
from typing import Literal

m: tuple[Literal["a"], None] | tuple[Literal["b"], int] = ("a", None)
match m:
case "a", None:
pass
case _:
pass
[builtins fixtures/tuple.pyi]

[case testMatchSequencePatternTupleStarred]
# flags: --strict-equality --warn-unreachable
from typing import Tuple
Expand Down
Loading