Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ddbce137
Commit
ddbce137
authored
Nov 15, 2017
by
Serhiy Storchaka
Committed by
GitHub
Nov 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-32023: Disallow genexprs without parenthesis in class definitions. (#4400)
parent
edad8eeb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
7 deletions
+23
-7
Doc/whatsnew/3.7.rst
Doc/whatsnew/3.7.rst
+6
-2
Lib/test/test_syntax.py
Lib/test/test_syntax.py
+4
-0
Misc/NEWS.d/next/Core and Builtins/2017-11-15-10-49-35.bpo-32023.XnCGT5.rst
...ore and Builtins/2017-11-15-10-49-35.bpo-32023.XnCGT5.rst
+3
-0
Python/ast.c
Python/ast.c
+10
-5
No files found.
Doc/whatsnew/3.7.rst
View file @
ddbce137
...
...
@@ -638,10 +638,14 @@ Changes in Python behavior
f(1 for x in [1],)
class C(1 for x in [1]):
pass
Python 3.7 now correctly raises a :exc:`SyntaxError`, as a generator
expression always needs to be directly inside a set of parentheses
and cannot have a comma on either side.
(Contributed by Serhiy Storchaka in :issue:`32012`.)
and cannot have a comma on either side, and the duplication of the
parentheses can be omitted only on calls.
(Contributed by Serhiy Storchaka in :issue:`32012` and :issue:`32023`.)
Changes in the Python API
...
...
Lib/test/test_syntax.py
View file @
ddbce137
...
...
@@ -153,6 +153,10 @@ Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized
>>> f((x for x in L), 1)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> class C(x for x in L):
... pass
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> def g(*args, **kwargs):
... print(args, sorted(kwargs.items()))
...
...
Misc/NEWS.d/next/Core and Builtins/2017-11-15-10-49-35.bpo-32023.XnCGT5.rst
0 → 100644
View file @
ddbce137
SyntaxError is now correctly raised when a generator expression without
parenthesis is used instead of an inheritance list in a class definition.
The duplication of the parentheses can be omitted only on calls.
Python/ast.c
View file @
ddbce137
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment