Skip to content

Commit 2e0ce80

Browse files
Fi test
1 parent 853b762 commit 2e0ce80

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mypy/checkpattern.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
247247
# get inner types of original type
248248
#
249249
# 1. Go through all possible types and filter to only those which are sequences that could match that number of items
250-
# 2. If there are multiple tuples left with unpacks, then use the fallback logic where we union all items types
251-
# 3. Otherwise, take the product of the item types so that each index can have a unique type
250+
# 2. If there is exactly one tuple left with an unpack, then use that type and the unpack index
251+
# 3. Otherwise, take the product of the item types so that each index can have a unique type. For tuples with unpack
252+
# fallback to merging all of their types for each index since we can't handle multiple unpacked items at once yet.
252253

253254
# state of matching
254255
state: (
@@ -303,7 +304,6 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
303304
state = ("MULTI_UNPACK", [[self.chk.iterable_item_type(tuple_fallback(state[1]), o)] * n_patterns])
304305
assert state[0] != "UNPACK" # for type checker
305306
state[1].append(inner_t)
306-
307307
if state[0] == "UNPACK":
308308
_, update_tuple_type, unpack_index, union_index = state
309309
inner_types = update_tuple_type.items

test-data/unit/check-python310.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,11 +1602,11 @@ match m6:
16021602
reveal_type(b6) # N: Revealed type is "Union[builtins.int, builtins.float, builtins.str]"
16031603

16041604
# but do still seperate types from non unpacked types
1605-
m7: tuple[int, Unpack[tuple[float, ...]]] | tuple[str, bool]
1605+
m7: tuple[int, Unpack[tuple[float, ...]]] | tuple[str, str]
16061606
match m7:
16071607
case (a7, b7, *rest7):
16081608
reveal_type(a7) # N: Revealed type is "Union[builtins.int, builtins.float, builtins.str]"
1609-
reveal_type(b7) # N: Revealed type is "Union[builtins.int, builtins.float, builtins.bool]"
1609+
reveal_type(b7) # N: Revealed type is "Union[builtins.int, builtins.float, builtins.str]"
16101610
reveal_type(rest7) # N: Revealed type is "builtins.list[Union[builtins.int, builtins.float]]"
16111611

16121612
# verify that if we are unpacking, it will get the type of the sequence if the tuple is too short

0 commit comments

Comments
 (0)