Skip to content

Commit 5d84cb3

Browse files
serhiy-storchakabenjaminp
authored andcommitted
bpo-31464: asdl_c.py no longer emits trailing spaces in Python-ast.h. (#3568)
1 parent b2e5794 commit 5d84cb3

File tree

2 files changed

+62
-61
lines changed

2 files changed

+62
-61
lines changed

Include/Python-ast.h

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ struct _mod {
4848
asdl_seq *body;
4949
string docstring;
5050
} Module;
51-
51+
5252
struct {
5353
asdl_seq *body;
5454
} Interactive;
55-
55+
5656
struct {
5757
expr_ty body;
5858
} Expression;
59-
59+
6060
struct {
6161
asdl_seq *body;
6262
} Suite;
63-
63+
6464
} v;
6565
};
6666

@@ -83,7 +83,7 @@ struct _stmt {
8383
expr_ty returns;
8484
string docstring;
8585
} FunctionDef;
86-
86+
8787
struct {
8888
identifier name;
8989
arguments_ty args;
@@ -92,7 +92,7 @@ struct _stmt {
9292
expr_ty returns;
9393
string docstring;
9494
} AsyncFunctionDef;
95-
95+
9696
struct {
9797
identifier name;
9898
asdl_seq *bases;
@@ -101,108 +101,108 @@ struct _stmt {
101101
asdl_seq *decorator_list;
102102
string docstring;
103103
} ClassDef;
104-
104+
105105
struct {
106106
expr_ty value;
107107
} Return;
108-
108+
109109
struct {
110110
asdl_seq *targets;
111111
} Delete;
112-
112+
113113
struct {
114114
asdl_seq *targets;
115115
expr_ty value;
116116
} Assign;
117-
117+
118118
struct {
119119
expr_ty target;
120120
operator_ty op;
121121
expr_ty value;
122122
} AugAssign;
123-
123+
124124
struct {
125125
expr_ty target;
126126
expr_ty annotation;
127127
expr_ty value;
128128
int simple;
129129
} AnnAssign;
130-
130+
131131
struct {
132132
expr_ty target;
133133
expr_ty iter;
134134
asdl_seq *body;
135135
asdl_seq *orelse;
136136
} For;
137-
137+
138138
struct {
139139
expr_ty target;
140140
expr_ty iter;
141141
asdl_seq *body;
142142
asdl_seq *orelse;
143143
} AsyncFor;
144-
144+
145145
struct {
146146
expr_ty test;
147147
asdl_seq *body;
148148
asdl_seq *orelse;
149149
} While;
150-
150+
151151
struct {
152152
expr_ty test;
153153
asdl_seq *body;
154154
asdl_seq *orelse;
155155
} If;
156-
156+
157157
struct {
158158
asdl_seq *items;
159159
asdl_seq *body;
160160
} With;
161-
161+
162162
struct {
163163
asdl_seq *items;
164164
asdl_seq *body;
165165
} AsyncWith;
166-
166+
167167
struct {
168168
expr_ty exc;
169169
expr_ty cause;
170170
} Raise;
171-
171+
172172
struct {
173173
asdl_seq *body;
174174
asdl_seq *handlers;
175175
asdl_seq *orelse;
176176
asdl_seq *finalbody;
177177
} Try;
178-
178+
179179
struct {
180180
expr_ty test;
181181
expr_ty msg;
182182
} Assert;
183-
183+
184184
struct {
185185
asdl_seq *names;
186186
} Import;
187-
187+
188188
struct {
189189
identifier module;
190190
asdl_seq *names;
191191
int level;
192192
} ImportFrom;
193-
193+
194194
struct {
195195
asdl_seq *names;
196196
} Global;
197-
197+
198198
struct {
199199
asdl_seq *names;
200200
} Nonlocal;
201-
201+
202202
struct {
203203
expr_ty value;
204204
} Expr;
205-
205+
206206
} v;
207207
int lineno;
208208
int col_offset;
@@ -224,145 +224,145 @@ struct _expr {
224224
boolop_ty op;
225225
asdl_seq *values;
226226
} BoolOp;
227-
227+
228228
struct {
229229
expr_ty left;
230230
operator_ty op;
231231
expr_ty right;
232232
} BinOp;
233-
233+
234234
struct {
235235
unaryop_ty op;
236236
expr_ty operand;
237237
} UnaryOp;
238-
238+
239239
struct {
240240
arguments_ty args;
241241
expr_ty body;
242242
} Lambda;
243-
243+
244244
struct {
245245
expr_ty test;
246246
expr_ty body;
247247
expr_ty orelse;
248248
} IfExp;
249-
249+
250250
struct {
251251
asdl_seq *keys;
252252
asdl_seq *values;
253253
} Dict;
254-
254+
255255
struct {
256256
asdl_seq *elts;
257257
} Set;
258-
258+
259259
struct {
260260
expr_ty elt;
261261
asdl_seq *generators;
262262
} ListComp;
263-
263+
264264
struct {
265265
expr_ty elt;
266266
asdl_seq *generators;
267267
} SetComp;
268-
268+
269269
struct {
270270
expr_ty key;
271271
expr_ty value;
272272
asdl_seq *generators;
273273
} DictComp;
274-
274+
275275
struct {
276276
expr_ty elt;
277277
asdl_seq *generators;
278278
} GeneratorExp;
279-
279+
280280
struct {
281281
expr_ty value;
282282
} Await;
283-
283+
284284
struct {
285285
expr_ty value;
286286
} Yield;
287-
287+
288288
struct {
289289
expr_ty value;
290290
} YieldFrom;
291-
291+
292292
struct {
293293
expr_ty left;
294294
asdl_int_seq *ops;
295295
asdl_seq *comparators;
296296
} Compare;
297-
297+
298298
struct {
299299
expr_ty func;
300300
asdl_seq *args;
301301
asdl_seq *keywords;
302302
} Call;
303-
303+
304304
struct {
305305
object n;
306306
} Num;
307-
307+
308308
struct {
309309
string s;
310310
} Str;
311-
311+
312312
struct {
313313
expr_ty value;
314314
int conversion;
315315
expr_ty format_spec;
316316
} FormattedValue;
317-
317+
318318
struct {
319319
asdl_seq *values;
320320
} JoinedStr;
321-
321+
322322
struct {
323323
bytes s;
324324
} Bytes;
325-
325+
326326
struct {
327327
singleton value;
328328
} NameConstant;
329-
329+
330330
struct {
331331
constant value;
332332
} Constant;
333-
333+
334334
struct {
335335
expr_ty value;
336336
identifier attr;
337337
expr_context_ty ctx;
338338
} Attribute;
339-
339+
340340
struct {
341341
expr_ty value;
342342
slice_ty slice;
343343
expr_context_ty ctx;
344344
} Subscript;
345-
345+
346346
struct {
347347
expr_ty value;
348348
expr_context_ty ctx;
349349
} Starred;
350-
350+
351351
struct {
352352
identifier id;
353353
expr_context_ty ctx;
354354
} Name;
355-
355+
356356
struct {
357357
asdl_seq *elts;
358358
expr_context_ty ctx;
359359
} List;
360-
360+
361361
struct {
362362
asdl_seq *elts;
363363
expr_context_ty ctx;
364364
} Tuple;
365-
365+
366366
} v;
367367
int lineno;
368368
int col_offset;
@@ -377,15 +377,15 @@ struct _slice {
377377
expr_ty upper;
378378
expr_ty step;
379379
} Slice;
380-
380+
381381
struct {
382382
asdl_seq *dims;
383383
} ExtSlice;
384-
384+
385385
struct {
386386
expr_ty value;
387387
} Index;
388-
388+
389389
} v;
390390
};
391391

@@ -405,7 +405,7 @@ struct _excepthandler {
405405
identifier name;
406406
asdl_seq *body;
407407
} ExceptHandler;
408-
408+
409409
} v;
410410
int lineno;
411411
int col_offset;

Parser/asdl_c.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ def emit(self, s, depth, reflow=True):
9494
else:
9595
lines = [s]
9696
for line in lines:
97-
line = (" " * TABSIZE * depth) + line + "\n"
98-
self.file.write(line)
97+
if line:
98+
line = (" " * TABSIZE * depth) + line
99+
self.file.write(line + "\n")
99100

100101

101102
class TypeDefVisitor(EmitVisitor):

0 commit comments

Comments
 (0)