File tree Expand file tree Collapse file tree 3 files changed +182
-0
lines changed
crates/ruff_python_parser/src/parser Expand file tree Collapse file tree 3 files changed +182
-0
lines changed Original file line number Diff line number Diff line change 1+ -- -
2+ source : crates / ruff_python_parser / src / parser / tests .rs
3+ expression : result
4+ -- -
5+ Parsed {
6+ syntax : ModExpression {
7+ node_index : NodeIndex (None ),
8+ range : 0..25 ,
9+ body : DictComp (
10+ ExprDictComp {
11+ node_index: NodeIndex (None ),
12+ range: 0..25 ,
13+ key: Name (
14+ ExprName {
15+ node_index: NodeIndex (None ),
16+ range: 1..2 ,
17+ id: Name (" x" ),
18+ ctx: Load ,
19+ },
20+ ),
21+ value: BinOp (
22+ ExprBinOp {
23+ node_index: NodeIndex (None ),
24+ range: 4..7 ,
25+ left: Name (
26+ ExprName {
27+ node_index: NodeIndex (None ),
28+ range: 7..7 ,
29+ id: Name (" " ),
30+ ctx: Invalid ,
31+ },
32+ ),
33+ op: Pow ,
34+ right: Name (
35+ ExprName {
36+ node_index: NodeIndex (None ),
37+ range: 6..7 ,
38+ id: Name (" y" ),
39+ ctx: Load ,
40+ },
41+ ),
42+ },
43+ ),
44+ generators: [
45+ Comprehension {
46+ range: 8..24 ,
47+ node_index: NodeIndex (None ),
48+ target: Tuple (
49+ ExprTuple {
50+ node_index: NodeIndex (None ),
51+ range: 12..16 ,
52+ elts: [
53+ Name (
54+ ExprName {
55+ node_index: NodeIndex (None ),
56+ range: 12..13 ,
57+ id: Name (" x" ),
58+ ctx: Store ,
59+ },
60+ ),
61+ Name (
62+ ExprName {
63+ node_index: NodeIndex (None ),
64+ range: 15..16 ,
65+ id: Name (" y" ),
66+ ctx: Store ,
67+ },
68+ ),
69+ ],
70+ ctx: Store ,
71+ parenthesized: false ,
72+ },
73+ ),
74+ iter: Name (
75+ ExprName {
76+ node_index: NodeIndex (None ),
77+ range: 20..24 ,
78+ id: Name (" data" ),
79+ ctx: Load ,
80+ },
81+ ),
82+ ifs: [],
83+ is_async: false ,
84+ },
85+ ],
86+ },
87+ ),
88+ },
89+ tokens : Tokens {
90+ raw : [
91+ Lbrace 0..1 ,
92+ Name 1..2 ,
93+ Colon 2..3 ,
94+ DoubleStar 4..6 ,
95+ Name 6..7 ,
96+ For 8..11 ,
97+ Name 12..13 ,
98+ Comma 13..14 ,
99+ Name 15..16 ,
100+ In 17..19 ,
101+ Name 20..24 ,
102+ Rbrace 24..25 ,
103+ Newline 25..25 ,
104+ ],
105+ },
106+ errors : [],
107+ unsupported_syntax_errors : [],
108+ }
Original file line number Diff line number Diff line change 1+ -- -
2+ source : crates / ruff_python_parser / src / parser / tests .rs
3+ expression : result
4+ -- -
5+ Parsed {
6+ syntax : ModExpression {
7+ node_index : NodeIndex (None ),
8+ range : 0..13 ,
9+ body : Call (
10+ ExprCall {
11+ node_index: NodeIndex (None ),
12+ range: 0..13 ,
13+ func: Name (
14+ ExprName {
15+ node_index: NodeIndex (None ),
16+ range: 0..3 ,
17+ id: Name (" foo" ),
18+ ctx: Load ,
19+ },
20+ ),
21+ arguments: Arguments {
22+ range: 3..13 ,
23+ node_index: NodeIndex (None ),
24+ args: [],
25+ keywords: [
26+ Keyword {
27+ range: 4..12 ,
28+ node_index: NodeIndex (None ),
29+ arg: None ,
30+ value: Name (
31+ ExprName {
32+ node_index: NodeIndex (None ),
33+ range: 6..12 ,
34+ id: Name (" kwargs" ),
35+ ctx: Load ,
36+ },
37+ ),
38+ },
39+ ],
40+ },
41+ },
42+ ),
43+ },
44+ tokens : Tokens {
45+ raw : [
46+ Name 0..3 ,
47+ Lpar 3..4 ,
48+ DoubleStar 4..6 ,
49+ Name 6..12 ,
50+ Rpar 12..13 ,
51+ Newline 13..13 ,
52+ ],
53+ },
54+ errors : [],
55+ unsupported_syntax_errors : [],
56+ }
Original file line number Diff line number Diff line change @@ -157,3 +157,21 @@ t"i}'"#;
157157
158158 insta:: assert_debug_snapshot!( error) ;
159159}
160+
161+ #[ test]
162+ fn test_dict_double_star_missing_left_operand ( ) {
163+ let source = r#"{x: **y for x, y in data}"# ;
164+ let parsed = parse_expression ( source) ;
165+ assert ! ( parsed. is_ok( ) ) ;
166+ let result = parsed. unwrap ( ) ;
167+ insta:: assert_debug_snapshot!( result) ;
168+ }
169+
170+ #[ test]
171+ fn test_function_kwargs ( ) {
172+ let source = r#"foo(**kwargs)"# ;
173+ let parsed = parse_expression ( source) ;
174+ assert ! ( parsed. is_ok( ) ) ;
175+ let result = parsed. unwrap ( ) ;
176+ insta:: assert_debug_snapshot!( result) ;
177+ }
You can’t perform that action at this time.
0 commit comments