bpo-32012: Disallow trailing comma after genexpr without parenthesis. · python/cpython@db4aafc · GitHub
Skip to content

Commit db4aafc

Browse files
bpo-32012: Disallow trailing comma after genexpr without parenthesis.
1 parent d7d4fea commit db4aafc

4 files changed

Lines changed: 45 additions & 13 deletions

File tree

Doc/whatsnew/3.7.rst

Lines changed: 14 additions & 0 deletions

Lib/test/test_syntax.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,32 @@
125125
126126
From ast_for_call():
127127
128-
>>> def f(it, *varargs):
128+
>>> def f(it, *varargs, **kwargs):
129129
... return list(it)
130130
>>> L = range(10)
131131
>>> f(x for x in L)
132132
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
133133
>>> f(x for x in L, 1)
134134
Traceback (most recent call last):
135-
SyntaxError: Generator expression must be parenthesized if not sole argument
135+
SyntaxError: Generator expression must be parenthesized
136+
>>> f(x for x in L, y=1)
137+
Traceback (most recent call last):
138+
SyntaxError: Generator expression must be parenthesized
139+
>>> f(x for x in L, *[])
140+
Traceback (most recent call last):
141+
SyntaxError: Generator expression must be parenthesized
142+
>>> f(x for x in L, **{})
143+
Traceback (most recent call last):
144+
SyntaxError: Generator expression must be parenthesized
145+
>>> f(L, x for x in L)
146+
Traceback (most recent call last):
147+
SyntaxError: Generator expression must be parenthesized
136148
>>> f(x for x in L, y for y in L)
137149
Traceback (most recent call last):
138-
SyntaxError: Generator expression must be parenthesized if not sole argument
150+
SyntaxError: Generator expression must be parenthesized
151+
>>> f(x for x in L,)
152+
Traceback (most recent call last):
153+
SyntaxError: Generator expression must be parenthesized
139154
>>> f((x for x in L), 1)
140155
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
141156
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SyntaxError now is raised when a generator expression without parenthesis is
2+
passed as argument but followed by trailing comma. A generator expression
3+
always needs to be directly inside a set of parentheses and cannot have a
4+
comma on either side.

Python/ast.c

Lines changed: 9 additions & 10 deletions

0 commit comments

Comments
 (0)