Skip to content

Commit fc5b356

Browse files
committed
Python: Add parser test for comprehensions with unpacking
1 parent 90b6461 commit fc5b356

File tree

2 files changed

+304
-0
lines changed

2 files changed

+304
-0
lines changed
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
Module: [4, 0] - [20, 0]
2+
body: [
3+
Expr: [4, 0] - [4, 15]
4+
value:
5+
ListComp: [4, 0] - [4, 15]
6+
elt: None
7+
generators: None
8+
function:
9+
Function: [4, 0] - [4, 15]
10+
name: 'listcomp'
11+
type_parameters: []
12+
args: [
13+
Name: [4, 0] - [4, 15]
14+
variable: Variable('.0', None)
15+
ctx: Param
16+
]
17+
vararg: None
18+
kwonlyargs: None
19+
kwarg: None
20+
body: [
21+
For: [4, 0] - [4, 15]
22+
target:
23+
Name: [4, 8] - [4, 9]
24+
variable: Variable('x', None)
25+
ctx: Store
26+
iter:
27+
Name: [4, 0] - [4, 15]
28+
variable: Variable('.0', None)
29+
ctx: Load
30+
body: [
31+
Expr: [4, 1] - [4, 3]
32+
value:
33+
YieldFrom: [4, 1] - [4, 3]
34+
value:
35+
Name: [4, 2] - [4, 3]
36+
variable: Variable('x', None)
37+
ctx: Load
38+
]
39+
orelse: None
40+
]
41+
iterable:
42+
Name: [4, 13] - [4, 14]
43+
variable: Variable('y', None)
44+
ctx: Load
45+
Expr: [7, 0] - [7, 15]
46+
value:
47+
SetComp: [7, 0] - [7, 15]
48+
elt: None
49+
generators: None
50+
function:
51+
Function: [7, 0] - [7, 15]
52+
name: 'setcomp'
53+
type_parameters: []
54+
args: [
55+
Name: [7, 0] - [7, 15]
56+
variable: Variable('.0', None)
57+
ctx: Param
58+
]
59+
vararg: None
60+
kwonlyargs: None
61+
kwarg: None
62+
body: [
63+
For: [7, 0] - [7, 15]
64+
target:
65+
Name: [7, 8] - [7, 9]
66+
variable: Variable('x', None)
67+
ctx: Store
68+
iter:
69+
Name: [7, 0] - [7, 15]
70+
variable: Variable('.0', None)
71+
ctx: Load
72+
body: [
73+
Expr: [7, 1] - [7, 3]
74+
value:
75+
YieldFrom: [7, 1] - [7, 3]
76+
value:
77+
Name: [7, 2] - [7, 3]
78+
variable: Variable('x', None)
79+
ctx: Load
80+
]
81+
orelse: None
82+
]
83+
iterable:
84+
Name: [7, 13] - [7, 14]
85+
variable: Variable('y', None)
86+
ctx: Load
87+
Expr: [10, 0] - [10, 20]
88+
value:
89+
DictComp: [10, 0] - [10, 20]
90+
key: None
91+
value: None
92+
generators: None
93+
function:
94+
Function: [10, 0] - [10, 20]
95+
name: 'dictcomp'
96+
type_parameters: []
97+
args: [
98+
Name: [10, 0] - [10, 20]
99+
variable: Variable('.0', None)
100+
ctx: Param
101+
]
102+
vararg: None
103+
kwonlyargs: None
104+
kwarg: None
105+
body: [
106+
For: [10, 0] - [10, 20]
107+
target:
108+
Name: [10, 9] - [10, 10]
109+
variable: Variable('d', None)
110+
ctx: Store
111+
iter:
112+
Name: [10, 0] - [10, 20]
113+
variable: Variable('.0', None)
114+
ctx: Load
115+
body: [
116+
Expr: [10, 1] - [10, 4]
117+
value:
118+
YieldFrom: [10, 1] - [10, 4]
119+
value:
120+
Call: [10, 3] - [10, 4]
121+
func:
122+
Attribute: [10, 3] - [10, 4]
123+
value:
124+
Name: [10, 3] - [10, 4]
125+
variable: Variable('d', None)
126+
ctx: Load
127+
attr: 'items'
128+
ctx: Load
129+
positional_args: []
130+
named_args: []
131+
]
132+
orelse: None
133+
]
134+
iterable:
135+
Name: [10, 14] - [10, 19]
136+
variable: Variable('dicts', None)
137+
ctx: Load
138+
Expr: [13, 0] - [13, 15]
139+
value:
140+
GeneratorExp: [13, 1] - [13, 14]
141+
elt: None
142+
generators: None
143+
function:
144+
Function: [13, 1] - [13, 14]
145+
name: 'genexpr'
146+
type_parameters: []
147+
args: [
148+
Name: [13, 1] - [13, 14]
149+
variable: Variable('.0', None)
150+
ctx: Param
151+
]
152+
vararg: None
153+
kwonlyargs: None
154+
kwarg: None
155+
body: [
156+
For: [13, 1] - [13, 14]
157+
target:
158+
Name: [13, 8] - [13, 9]
159+
variable: Variable('x', None)
160+
ctx: Store
161+
iter:
162+
Name: [13, 1] - [13, 14]
163+
variable: Variable('.0', None)
164+
ctx: Load
165+
body: [
166+
Expr: [13, 1] - [13, 3]
167+
value:
168+
YieldFrom: [13, 1] - [13, 3]
169+
value:
170+
Name: [13, 2] - [13, 3]
171+
variable: Variable('x', None)
172+
ctx: Load
173+
]
174+
orelse: None
175+
]
176+
iterable:
177+
Name: [13, 13] - [13, 14]
178+
variable: Variable('y', None)
179+
ctx: Load
180+
parenthesised: True
181+
Expr: [16, 0] - [16, 20]
182+
value:
183+
ListComp: [16, 0] - [16, 20]
184+
elt: None
185+
generators: None
186+
function:
187+
Function: [16, 0] - [16, 20]
188+
name: 'listcomp'
189+
type_parameters: []
190+
args: [
191+
Name: [16, 0] - [16, 20]
192+
variable: Variable('.0', None)
193+
ctx: Param
194+
]
195+
vararg: None
196+
kwonlyargs: None
197+
kwarg: None
198+
body: [
199+
For: [16, 0] - [16, 20]
200+
target:
201+
Name: [16, 8] - [16, 9]
202+
variable: Variable('x', None)
203+
ctx: Store
204+
iter:
205+
Name: [16, 0] - [16, 20]
206+
variable: Variable('.0', None)
207+
ctx: Load
208+
body: [
209+
If: [16, 18] - [16, 19]
210+
test:
211+
Name: [16, 18] - [16, 19]
212+
variable: Variable('x', None)
213+
ctx: Load
214+
body: [
215+
Expr: [16, 1] - [16, 3]
216+
value:
217+
YieldFrom: [16, 1] - [16, 3]
218+
value:
219+
Name: [16, 2] - [16, 3]
220+
variable: Variable('x', None)
221+
ctx: Load
222+
]
223+
orelse: None
224+
]
225+
orelse: None
226+
]
227+
iterable:
228+
Name: [16, 13] - [16, 14]
229+
variable: Variable('y', None)
230+
ctx: Load
231+
Expr: [19, 0] - [19, 26]
232+
value:
233+
ListComp: [19, 0] - [19, 26]
234+
elt: None
235+
generators: None
236+
function:
237+
Function: [19, 0] - [19, 26]
238+
name: 'listcomp'
239+
type_parameters: []
240+
args: [
241+
Name: [19, 0] - [19, 26]
242+
variable: Variable('.0', None)
243+
ctx: Param
244+
]
245+
vararg: None
246+
kwonlyargs: None
247+
kwarg: None
248+
body: [
249+
For: [19, 0] - [19, 26]
250+
target:
251+
Name: [19, 8] - [19, 9]
252+
variable: Variable('y', None)
253+
ctx: Store
254+
iter:
255+
Name: [19, 0] - [19, 26]
256+
variable: Variable('.0', None)
257+
ctx: Load
258+
body: [
259+
For: [19, 0] - [19, 26]
260+
target:
261+
Name: [19, 19] - [19, 20]
262+
variable: Variable('x', None)
263+
ctx: Store
264+
iter:
265+
Name: [19, 24] - [19, 25]
266+
variable: Variable('y', None)
267+
ctx: Load
268+
body: [
269+
Expr: [19, 1] - [19, 3]
270+
value:
271+
YieldFrom: [19, 1] - [19, 3]
272+
value:
273+
Name: [19, 2] - [19, 3]
274+
variable: Variable('x', None)
275+
ctx: Load
276+
]
277+
orelse: None
278+
]
279+
orelse: None
280+
]
281+
iterable:
282+
Name: [19, 13] - [19, 14]
283+
variable: Variable('z', None)
284+
ctx: Load
285+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# PEP 798: Unpacking in comprehensions
2+
3+
# Star unpacking in list comprehension
4+
[*x for x in y]
5+
6+
# Star unpacking in set comprehension
7+
{*x for x in y}
8+
9+
# Double-star unpacking in dict comprehension
10+
{**d for d in dicts}
11+
12+
# Star unpacking in generator expression
13+
(*x for x in y)
14+
15+
# With conditions
16+
[*x for x in y if x]
17+
18+
# Multiple for clauses
19+
[*x for y in z for x in y]

0 commit comments

Comments
 (0)