bpo-32023: Disallow genexprs without parenthesis in class definitions… · python/cpython@ddbce13 · GitHub
Skip to content

Commit ddbce13

Browse files
bpo-32023: Disallow genexprs without parenthesis in class definitions. (#4400)
1 parent edad8ee commit ddbce13

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

Doc/whatsnew/3.7.rst

Lines changed: 6 additions & 2 deletions

Lib/test/test_syntax.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@
153153
SyntaxError: Generator expression must be parenthesized
154154
>>> f((x for x in L), 1)
155155
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
156+
>>> class C(x for x in L):
157+
... pass
158+
Traceback (most recent call last):
159+
SyntaxError: invalid syntax
156160
157161
>>> def g(*args, **kwargs):
158162
... print(args, sorted(kwargs.items()))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SyntaxError is now correctly raised when a generator expression without
2+
parenthesis is used instead of an inheritance list in a class definition.
3+
The duplication of the parentheses can be omitted only on calls.

Python/ast.c

Lines changed: 10 additions & 5 deletions

0 commit comments

Comments
 (0)