Skip to content

Commit 5db0753

Browse files
committed
Improve MappingPattern rest location
1 parent 69112dd commit 5db0753

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/fastparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ def visit_MatchMapping(self, n: ast3.MatchMapping) -> MappingPattern:
17991799
if n.rest is None:
18001800
rest = None
18011801
else:
1802-
rest = NameExpr(n.rest)
1802+
rest = self.set_line(NameExpr(n.rest), n)
18031803

18041804
node = MappingPattern(keys, values, rest)
18051805
return self.set_line(node, n)

test-data/unit/check-python310.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,3 +3194,14 @@ def fun(val: str | None):
31943194
case types.NoneType():
31953195
reveal_type(val) # N: Revealed type is "None"
31963196
[builtins fixtures/tuple.pyi]
3197+
3198+
[case testMatchMappingRestErrorLocation]
3199+
data: list[int]
3200+
match data:
3201+
case [1, *rest]:
3202+
...
3203+
config: dict[str, object]
3204+
match config:
3205+
case {"a": 1, **rest}: # E: Incompatible types in capture pattern (pattern captures type "dict[str, object]", variable has type "list[int]")
3206+
...
3207+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)