Message324118
[From https://stackoverflow.com/q/52026406/270986]
The following is valid, and works as expected:
>>> def f():
... x = *(1, 2), 3
... return x
...
>>> f()
(1, 2, 3)
But the tuple expression can't be used directly in a "return" statement:
>>> def f():
... return *(1, 2), 3
File "<stdin>", line 2
return *(1, 2), 3
^
SyntaxError: invalid syntax
It's trivial to work around, by adding an extra pair of parentheses around the return target, but it seems a surprising inconsistency. Would it make sense to allow this? In terms of the grammar,
return_stmt: 'return' [testlist]
would be replaced with:
return_stmt: 'return' [testlist_star_expr]
There may be other places in the grammar where "testlist" could reasonably be replaced with "testlist_star_expr", for example:
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] |
|
Date |
User |
Action |
Args |
2018-08-26 14:25:51 | mark.dickinson | set | recipients:
+ mark.dickinson |
2018-08-26 14:25:50 | mark.dickinson | set | messageid: <1535293550.9.0.56676864532.issue34508@psf.upfronthosting.co.za> |
2018-08-26 14:25:50 | mark.dickinson | link | issue34508 messages |
2018-08-26 14:25:50 | mark.dickinson | create | |
|