summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-15 06:49:40 (GMT)
committerGitHub <noreply@github.com>2017-11-15 06:49:40 (GMT)
commit9165f77d5f93a2c12aa0e90853e3ae7212800d3c (patch)
tree96b831acd89b33f865d0be34bdbf5b7431c780c0 /Python/ast.c
parent3bda02222aa3783bf85fc3ff8bc042aefd9c4fd3 (diff)
downloadcpython-9165f77d5f93a2c12aa0e90853e3ae7212800d3c.zip
cpython-9165f77d5f93a2c12aa0e90853e3ae7212800d3c.tar.gz
cpython-9165f77d5f93a2c12aa0e90853e3ae7212800d3c.tar.bz2
bpo-32012: Disallow trailing comma after genexpr without parenthesis. (#4382)
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 79cef70..c88e7e3 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2712,7 +2712,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
argument: ( test [comp_for] | '*' test | test '=' test | '**' test )
*/
- int i, nargs, nkeywords, ngens;
+ int i, nargs, nkeywords;
int ndoublestars;
asdl_seq *args;
asdl_seq *keywords;
@@ -2721,14 +2721,18 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
nargs = 0;
nkeywords = 0;
- ngens = 0;
for (i = 0; i < NCH(n); i++) {
node *ch = CHILD(n, i);
if (TYPE(ch) == argument) {
if (NCH(ch) == 1)
nargs++;
- else if (TYPE(CHILD(ch, 1)) == comp_for)
- ngens++;
+ else if (TYPE(CHILD(ch, 1)) == comp_for) {
+ nargs++;
+ if (NCH(n) > 1) {
+ ast_error(c, ch, "Generator expression must be parenthesized");
+ return NULL;
+ }
+ }
else if (TYPE(CHILD(ch, 0)) == STAR)
nargs++;
else
@@ -2736,13 +2740,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
nkeywords++;
}
}
- if (ngens > 1 || (ngens && (nargs || nkeywords))) {
- ast_error(c, n, "Generator expression must be parenthesized "
- "if not sole argument");
- return NULL;
- }
- args = _Py_asdl_seq_new(nargs + ngens, c->c_arena);
+ args = _Py_asdl_seq_new(nargs, c->c_arena);
if (!args)
return NULL;
keywords = _Py_asdl_seq_new(nkeywords, c->c_arena);