File tree Expand file tree Collapse file tree
crates/ruff_python_parser Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ match [0 ]: int
2+ match [x , y , z ]: dict
Original file line number Diff line number Diff line change @@ -2448,6 +2448,9 @@ impl<'src> Parser<'src> {
24482448 let subject = self . parse_match_subject_expression ( ) ;
24492449
24502450 match self . current_token_kind ( ) {
2451+ // test_ok match_annotated_assignment
2452+ // match[0]: int
2453+ // match [x, y, z]: dict
24512454 TokenKind :: Colon if self . peek ( ) == TokenKind :: Newline => {
24522455 // `match` is a keyword — colon followed by newline confirms
24532456 // this is a match statement, not an annotated assignment like
Original file line number Diff line number Diff line change 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..36 ,
11+ body : [
12+ AnnAssign (
13+ StmtAnnAssign {
14+ node_index: NodeIndex (None ),
15+ range: 0..13 ,
16+ target: Subscript (
17+ ExprSubscript {
18+ node_index: NodeIndex (None ),
19+ range: 0..8 ,
20+ value: Name (
21+ ExprName {
22+ node_index: NodeIndex (None ),
23+ range: 0..5 ,
24+ id: Name (" match" ),
25+ ctx: Load ,
26+ },
27+ ),
28+ slice: NumberLiteral (
29+ ExprNumberLiteral {
30+ node_index: NodeIndex (None ),
31+ range: 6..7 ,
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: 10..13 ,
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: 14..35 ,
56+ target: Subscript (
57+ ExprSubscript {
58+ node_index: NodeIndex (None ),
59+ range: 14..29 ,
60+ value: Name (
61+ ExprName {
62+ node_index: NodeIndex (None ),
63+ range: 14..19 ,
64+ id: Name (" match" ),
65+ ctx: Load ,
66+ },
67+ ),
68+ slice: Tuple (
69+ ExprTuple {
70+ node_index: NodeIndex (None ),
71+ range: 21..28 ,
72+ elts: [
73+ Name (
74+ ExprName {
75+ node_index: NodeIndex (None ),
76+ range: 21..22 ,
77+ id: Name (" x" ),
78+ ctx: Load ,
79+ },
80+ ),
81+ Name (
82+ ExprName {
83+ node_index: NodeIndex (None ),
84+ range: 24..25 ,
85+ id: Name (" y" ),
86+ ctx: Load ,
87+ },
88+ ),
89+ Name (
90+ ExprName {
91+ node_index: NodeIndex (None ),
92+ range: 27..28 ,
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: 31..35 ,
109+ id: Name (" dict" ),
110+ ctx: Load ,
111+ },
112+ ),
113+ value: None ,
114+ simple: false ,
115+ },
116+ ),
117+ ],
118+ } ,
119+ )
120+ ` ` `
You can’t perform that action at this time.
0 commit comments