[Python-checkins] bpo-39235: Fix end location for genexp in call args (GH-17925)
Miss Islington (bot)
webhook-mailer at python.org
Thu Jan 9 14:39:10 EST 2020
https://github.com/python/cpython/commit/33e033da3c1472b0aa2ae3cff06649a1ae4aa37f
commit: 33e033da3c1472b0aa2ae3cff06649a1ae4aa37f
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-01-09T11:39:00-08:00
summary:
bpo-39235: Fix end location for genexp in call args (GH-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
(cherry picked from commit a796d8ef9dd1af65f7e4d7a857b56f35b7cb6e78)
Co-authored-by: Guido van Rossum <guido at python.org>
files:
A Misc/NEWS.d/next/Core and Builtins/2020-01-09-10-01-18.bpo-39235.RYwjoc.rst
M Python/ast.c
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-01-09-10-01-18.bpo-39235.RYwjoc.rst b/Misc/NEWS.d/next/Core and Builtins/2020-01-09-10-01-18.bpo-39235.RYwjoc.rst
new file mode 100644
index 0000000000000..5fb0d45356bad
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-01-09-10-01-18.bpo-39235.RYwjoc.rst
@@ -0,0 +1,2 @@
+Fix AST end location for lone generator expression in function call, e.g.
+f(i for i in a).
diff --git a/Python/ast.c b/Python/ast.c
index 6cf71ce7bb810..f3263c1e3fcdc 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1028,13 +1028,13 @@ forbidden_name(struct compiling *c, identifier name, const node *n,
}
static expr_ty
-copy_location(expr_ty e, const node *n)
+copy_location(expr_ty e, const node *n, const node *end)
{
if (e) {
e->lineno = LINENO(n);
e->col_offset = n->n_col_offset;
- e->end_lineno = n->n_end_lineno;
- e->end_col_offset = n->n_end_col_offset;
+ e->end_lineno = end->n_end_lineno;
+ e->end_col_offset = end->n_end_col_offset;
}
return e;
}
@@ -2464,10 +2464,10 @@ ast_for_atom(struct compiling *c, const node *n)
}
if (TYPE(CHILD(ch, 1)) == comp_for) {
- return copy_location(ast_for_genexp(c, ch), n);
+ return copy_location(ast_for_genexp(c, ch), n, n);
}
else {
- return copy_location(ast_for_testlist(c, ch), n);
+ return copy_location(ast_for_testlist(c, ch), n, n);
}
case LSQB: /* list (or list comprehension) */
ch = CHILD(n, 1);
@@ -2486,7 +2486,7 @@ ast_for_atom(struct compiling *c, const node *n)
n->n_end_lineno, n->n_end_col_offset, c->c_arena);
}
else {
- return copy_location(ast_for_listcomp(c, ch), n);
+ return copy_location(ast_for_listcomp(c, ch), n, n);
}
case LBRACE: {
/* dictorsetmaker: ( ((test ':' test | '**' test)
@@ -2527,7 +2527,7 @@ ast_for_atom(struct compiling *c, const node *n)
/* It's a dictionary display. */
res = ast_for_dictdisplay(c, ch);
}
- return copy_location(res, n);
+ return copy_location(res, n, n);
}
}
default:
@@ -3146,7 +3146,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func,
}
else if (TYPE(CHILD(ch, 1)) == comp_for) {
/* the lone generator expression */
- e = copy_location(ast_for_genexp(c, ch), maybegenbeg);
+ e = copy_location(ast_for_genexp(c, ch), maybegenbeg, closepar);
if (!e)
return NULL;
asdl_seq_SET(args, nargs++, e);
More information about the Python-checkins
mailing list