8000 bpo-39235: Fix end location for genexp in call args (GH-17925) · shihai1991/cpython@926e087 · GitHub
[go: up one dir, main page]

Skip to content

Commit 926e087

Browse files
gvanrossumshihai1991
authored andcommitted
bpo-39235: Fix end location for genexp in call args (pythonGH-17925)
The fix changes copy_location() to require an extra node from which to extract the end location, and fixing all 5 call sites. https://bugs.python.org/issue39235
1 parent 106d785 commit 926e087

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix AST end location for lone generator expression in function call, e.g.
2+
f(i for i in a).

Python/ast.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,13 +1028,13 @@ forbidden_name(struct compiling *c, identifier name, const node *n,
10281028
}
10291029

10301030
static expr_ty
1031-
copy_location(expr_ty e, const node *n)
1031+
copy_location(expr_ty e, const node *n, const node *end)
10321032
{
10331033
if (e) {
10341034
e->lineno = LINENO(n);
10351035
e->col_offset = n->n_col_offset;
1036-
e->end_lineno = n->n_end_lineno;
1037-
e->end_col_offset = n->n_end_col_offset;
1036+
e->end_lineno = end->n_end_lineno;
1037+
e->end_col_offset = end->n_end_col_offset;
10381038
}
10391039
return e;
10401040
}
@@ -2464,10 +2464,10 @@ ast_for_atom(struct compiling *c, const node *n)
24642464
}
24652465

24662466
if (TYPE(CHILD(ch, 1)) == comp_for) {
2467-
return copy_location(ast_for_genexp(c, ch), n);
2467+
return copy_location(ast_for_genexp(c, ch), n, n);
24682468
}
24692469
else {
2470-
return copy_location(ast_for_testlist(c, ch), n);
2470+
return copy_location(ast_for_testlist(c, ch), n, n);
24712471
}
24722472
case LSQB: /* list (or list comprehension) */
24732473
ch = CHILD(n, 1);
@@ -2486,7 +2486,7 @@ ast_for_atom(struct compiling *c, const node *n)
24862486
n->n_end_lineno, n->n_end_col_offset, c->c_arena);
24872487
}
24882488
else {
2489-
return copy_location(ast_for_listcomp(c, ch), n);
2489+
return copy_location(ast_for_listcomp(c, ch), n, n);
24902490
}
24912491
case LBRACE: {
24922492
/* dictorsetmaker: ( ((test ':' test | '**' test)
@@ -2527,7 +2527,7 @@ ast_for_atom(struct compiling *c, const node *n)
25272527
/* It's a dictionary display. */
25282528
res = ast_for_dictdisplay(c, ch);
25292529
}
2530-
return copy_location(res, n);
2530+
return copy_location(res, n, n);
25312531
}
25322532
}
25332533
default:
@@ -3146,7 +3146,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func,
31463146
}
31473147
else if (TYPE(CHILD(ch, 1)) == comp_for) {
31483148
/* the lone generator expression */
3149-
e = copy_location(ast_for_genexp(c, ch), maybegenbeg);
3149+
e = copy_location(ast_for_genexp(c, ch), maybegenbeg, closepar);
31503150
if (!e)
31513151
return NULL;
31523152
asdl_seq_SET(args, nargs++, e);

0 commit comments

Comments
 (0)
0