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
2 changes: 1 addition & 1 deletion mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def visit_or_pattern(self, o: OrPattern) -> PatternType:
for capture_list in capture_types.values():
typ = UninhabitedType()
for _, other in capture_list:
typ = join_types(typ, other)
typ = make_simplified_union([typ, other])

captures[capture_list[0][0]] = typ

Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -1204,13 +1204,13 @@ match m:
case 1 | "foo":
reveal_type(m) # N: Revealed type is "Union[Literal[1], Literal['foo']]"

[case testMatchOrPatterCapturesMissing]
[case testMatchOrPatternCapturesMissing]
from typing import List
m: List[int]

match m:
case [x, y] | list(x): # E: Alternative patterns bind different names
reveal_type(x) # N: Revealed type is "builtins.object"
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.list[builtins.int]]"
reveal_type(y) # N: Revealed type is "builtins.int"
[builtins fixtures/list.pyi]

Expand All @@ -1219,7 +1219,7 @@ m: object

match m:
case list(x) | dict(x):
reveal_type(x) # N: Revealed type is "typing.Iterable[Any]"
reveal_type(x) # N: Revealed type is "Union[builtins.list[Any], builtins.dict[Any, Any]]"
[builtins fixtures/dict.pyi]

-- Interactions --
Expand Down Expand Up @@ -1405,7 +1405,7 @@ m: Union[str, bytes, int]

match m:
case str(a) | bytes(a):
reveal_type(a) # N: Revealed type is "builtins.object"
reveal_type(a) # N: Revealed type is "Union[builtins.str, builtins.bytes]"
reveal_type(m) # N: Revealed type is "Union[builtins.str, builtins.bytes]"
case b:
reveal_type(b) # N: Revealed type is "builtins.int"
Expand Down
Loading