Skip to content

Commit 50e4862

Browse files
committed
Add regression test for match-like annotated assignments (#22528)
1 parent 5daf99a commit 50e4862

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Regression test for https://github.com/astral-sh/ruff/issues/22528
2+
# These are annotated assignments using `match` as an identifier,
3+
# not match statements. The parser should not report a syntax error.
4+
match[0]: int
5+
match [x, y, z]: dict
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
source: crates/ruff_python_parser/tests/fixtures.rs
3+
---
4+
## AST
5+
6+
```
7+
Module(
8+
ModModule {
9+
node_index: NodeIndex(None),
10+
range: 0..240,
11+
body: [
12+
AnnAssign(
13+
StmtAnnAssign {
14+
node_index: NodeIndex(None),
15+
range: 204..217,
16+
target: Subscript(
17+
ExprSubscript {
18+
node_index: NodeIndex(None),
19+
range: 204..212,
20+
value: Name(
21+
ExprName {
22+
node_index: NodeIndex(None),
23+
range: 204..209,
24+
id: Name("match"),
25+
ctx: Load,
26+
},
27+
),
28+
slice: NumberLiteral(
29+
ExprNumberLiteral {
30+
node_index: NodeIndex(None),
31+
range: 210..211,
32+
value: Int(
33+
0,
34+
),
35+
},
36+
),
37+
ctx: Store,
38+
},
39+
),
40+
annotation: Name(
41+
ExprName {
42+
node_index: NodeIndex(None),
43+
range: 214..217,
44+
id: Name("int"),
45+
ctx: Load,
46+
},
47+
),
48+
value: None,
49+
simple: false,
50+
},
51+
),
52+
AnnAssign(
53+
StmtAnnAssign {
54+
node_index: NodeIndex(None),
55+
range: 218..239,
56+
target: Subscript(
57+
ExprSubscript {
58+
node_index: NodeIndex(None),
59+
range: 218..233,
60+
value: Name(
61+
ExprName {
62+
node_index: NodeIndex(None),
63+
range: 218..223,
64+
id: Name("match"),
65+
ctx: Load,
66+
},
67+
),
68+
slice: Tuple(
69+
ExprTuple {
70+
node_index: NodeIndex(None),
71+
range: 225..232,
72+
elts: [
73+
Name(
74+
ExprName {
75+
node_index: NodeIndex(None),
76+
range: 225..226,
77+
id: Name("x"),
78+
ctx: Load,
79+
},
80+
),
81+
Name(
82+
ExprName {
83+
node_index: NodeIndex(None),
84+
range: 228..229,
85+
id: Name("y"),
86+
ctx: Load,
87+
},
88+
),
89+
Name(
90+
ExprName {
91+
node_index: NodeIndex(None),
92+
range: 231..232,
93+
id: Name("z"),
94+
ctx: Load,
95+
},
96+
),
97+
],
98+
ctx: Load,
99+
parenthesized: false,
100+
},
101+
),
102+
ctx: Store,
103+
},
104+
),
105+
annotation: Name(
106+
ExprName {
107+
node_index: NodeIndex(None),
108+
range: 235..239,
109+
id: Name("dict"),
110+
ctx: Load,
111+
},
112+
),
113+
value: None,
114+
simple: false,
115+
},
116+
),
117+
],
118+
},
119+
)
120+
```

0 commit comments

Comments
 (0)