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
3 changes: 2 additions & 1 deletion mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def visit_or_pattern(self, o: OrPattern) -> PatternType:
for pattern in o.patterns:
pattern_type = self.accept(pattern, current_type)
pattern_types.append(pattern_type)
current_type = pattern_type.rest_type
if not is_uninhabited(pattern_type.type):
current_type = pattern_type.rest_type

#
# Collect the final type
Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,22 @@ def f(x: int | str) -> int:
case str() as s:
return 1

[case testMatchOrPatternExhaustiveness]
from typing import NoReturn, Literal
def assert_never(x: NoReturn) -> None: ...

Color = Literal["blue", "green", "red"]
c: Color

match c:
case "blue":
reveal_type(c) # N: Revealed type is "Literal['blue']"
case "green" | "notColor":
reveal_type(c) # N: Revealed type is "Literal['green']"
case _:
assert_never(c) # E: Argument 1 to "assert_never" has incompatible type "Literal['red']"; expected "Never"
[typing fixtures/typing-typeddict.pyi]

[case testMatchAsPatternIntersection-skip]
class A: pass
class B: pass
Expand Down
Loading