mirror of
https://github.com/python/cpython.git
synced 2025-08-28 20:56:54 +00:00
bpo-32012: Disallow trailing comma after genexpr without parenthesis. (#4382)
This commit is contained in:
parent
3bda02222a
commit
9165f77d5f
4 changed files with 45 additions and 13 deletions
|
@ -125,17 +125,32 @@ SyntaxError: invalid syntax
|
|||
|
||||
From ast_for_call():
|
||||
|
||||
>>> def f(it, *varargs):
|
||||
>>> def f(it, *varargs, **kwargs):
|
||||
... return list(it)
|
||||
>>> L = range(10)
|
||||
>>> f(x for x in L)
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
>>> f(x for x in L, 1)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Generator expression must be parenthesized if not sole argument
|
||||
SyntaxError: Generator expression must be parenthesized
|
||||
>>> f(x for x in L, y=1)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Generator expression must be parenthesized
|
||||
>>> f(x for x in L, *[])
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Generator expression must be parenthesized
|
||||
>>> f(x for x in L, **{})
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Generator expression must be parenthesized
|
||||
>>> f(L, x for x in L)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Generator expression must be parenthesized
|
||||
>>> f(x for x in L, y for y in L)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Generator expression must be parenthesized if not sole argument
|
||||
SyntaxError: Generator expression must be parenthesized
|
||||
>>> f(x for x in L,)
|
||||
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]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue