11
11
#include "pythonrun.h"
12
12
13
13
#include <assert.h>
14
+ #include <stdbool.h>
14
15
15
16
static int validate_stmts (asdl_seq * );
16
17
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);
611
612
static stmt_ty ast_for_for_stmt (struct compiling * , const node * , int );
612
613
613
614
/* Note different signature for ast_for_call */
614
- static expr_ty ast_for_call (struct compiling * , const node * , expr_ty );
615
+ static expr_ty ast_for_call (struct compiling * , const node * , expr_ty , bool );
615
616
616
617
static PyObject * parsenumber (struct compiling * , const char * );
617
618
static expr_ty parsestrplus (struct compiling * , const node * n );
@@ -1545,7 +1546,7 @@ ast_for_decorator(struct compiling *c, const node *n)
1545
1546
name_expr = NULL ;
1546
1547
}
1547
1548
else {
1548
- d = ast_for_call (c , CHILD (n , 3 ), name_expr );
1549
+ d = ast_for_call (c , CHILD (n , 3 ), name_expr , true );
1549
1550
if (!d )
1550
1551
return NULL ;
1551
1552
name_expr = NULL ;
@@ -2368,7 +2369,7 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
2368
2369
return Call (left_expr , NULL , NULL , LINENO (n ),
2369
2370
n -> n_col_offset , c -> c_arena );
2370
2371
else
2371
- return ast_for_call (c , CHILD (n , 1 ), left_expr );
2372
+ return ast_for_call (c , CHILD (n , 1 ), left_expr , true );
2372
2373
}
2373
2374
else if (TYPE (CHILD (n , 0 )) == DOT ) {
2374
2375
PyObject * attr_id = NEW_IDENTIFIER (CHILD (n , 1 ));
@@ -2705,7 +2706,7 @@ ast_for_expr(struct compiling *c, const node *n)
2705
2706
}
2706
2707
2707
2708
static expr_ty
2708
- ast_for_call (struct compiling * c , const node * n , expr_ty func )
2709
+ ast_for_call (struct compiling * c , const node * n , expr_ty func , bool allowgen )
2709
2710
{
2710
2711
/*
2711
2712
arglist: argument (',' argument)* [',']
@@ -2728,6 +2729,10 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
2728
2729
nargs ++ ;
2729
2730
else if (TYPE (CHILD (ch , 1 )) == comp_for ) {
2730
2731
nargs ++ ;
2732
+ if (!allowgen ) {
2733
+ ast_error (c , ch , "invalid syntax" );
2734
+ return NULL ;
2735
+ }
2731
2736
if (NCH (n ) > 1 ) {
2732
2737
ast_error (c , ch , "Generator expression must be parenthesized" );
2733
2738
return NULL ;
@@ -3973,7 +3978,7 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
3973
3978
if (!dummy_name )
3974
3979
return NULL ;
3975
3980
dummy = Name (dummy_name , Load , LINENO (n ), n -> n_col_offset , c -> c_arena );
3976
- call = ast_for_call (c , CHILD (n , 3 ), dummy );
3981
+ call = ast_for_call (c , CHILD (n , 3 ), dummy , false );
3977
3982
if (!call )
3978
3983
return NULL ;
3979
3984
}
0 commit comments