summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-15 15:39:37 (GMT)
committerGitHub <noreply@github.com>2017-11-15 15:39:37 (GMT)
commitddbce1378644f9d5ad0651e1c9035bd8c6502edc (patch)
tree73cd927d1c2b3bcaa6f5d6ad4bbf9d95927c5f3b /Python/ast.c
parentedad8eebeee3c99e324a7f1ac5073167c2b0b54d (diff)
downloadcpython-ddbce1378644f9d5ad0651e1c9035bd8c6502edc.zip
cpython-ddbce1378644f9d5ad0651e1c9035bd8c6502edc.tar.gz
cpython-ddbce1378644f9d5ad0651e1c9035bd8c6502edc.tar.bz2
bpo-32023: Disallow genexprs without parenthesis in class definitions. (#4400)
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Python/ast.c b/Python/ast.c
index c88e7e3..e44ce51 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -11,6 +11,7 @@
#include "pythonrun.h"
#include <assert.h>
+#include <stdbool.h>
static int validate_stmts(asdl_seq *);
static int validate_exprs(asdl_seq *, expr_context_ty, int);
@@ -611,7 +612,7 @@ static stmt_ty ast_for_with_stmt(struct compiling *, const node *, int);
static stmt_ty ast_for_for_stmt(struct compiling *, const node *, int);
/* Note different signature for ast_for_call */
-static expr_ty ast_for_call(struct compiling *, const node *, expr_ty);
+static expr_ty ast_for_call(struct compiling *, const node *, expr_ty, bool);
static PyObject *parsenumber(struct compiling *, const char *);
static expr_ty parsestrplus(struct compiling *, const node *n);
@@ -1545,7 +1546,7 @@ ast_for_decorator(struct compiling *c, const node *n)
name_expr = NULL;
}
else {
- d = ast_for_call(c, CHILD(n, 3), name_expr);
+ d = ast_for_call(c, CHILD(n, 3), name_expr, true);
if (!d)
return NULL;
name_expr = NULL;
@@ -2368,7 +2369,7 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
return Call(left_expr, NULL, NULL, LINENO(n),
n->n_col_offset, c->c_arena);
else
- return ast_for_call(c, CHILD(n, 1), left_expr);
+ return ast_for_call(c, CHILD(n, 1), left_expr, true);
}
else if (TYPE(CHILD(n, 0)) == DOT) {
PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1));
@@ -2705,7 +2706,7 @@ ast_for_expr(struct compiling *c, const node *n)
}
static expr_ty
-ast_for_call(struct compiling *c, const node *n, expr_ty func)
+ast_for_call(struct compiling *c, const node *n, expr_ty func, bool allowgen)
{
/*
arglist: argument (',' argument)* [',']
@@ -2728,6 +2729,10 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
nargs++;
else if (TYPE(CHILD(ch, 1)) == comp_for) {
nargs++;
+ if (!allowgen) {
+ ast_error(c, ch, "invalid syntax");
+ return NULL;
+ }
if (NCH(n) > 1) {
ast_error(c, ch, "Generator expression must be parenthesized");
return NULL;
@@ -3973,7 +3978,7 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
if (!dummy_name)
return NULL;
dummy = Name(dummy_name, Load, LINENO(n), n->n_col_offset, c->c_arena);
- call = ast_for_call(c, CHILD(n, 3), dummy);
+ call = ast_for_call(c, CHILD(n, 3), dummy, false);
if (!call)
return NULL;
}