This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson
Date 2018-08-26.14:25:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1535293550.9.0.56676864532.issue34508@psf.upfronthosting.co.za>
In-reply-to
Content
[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]
History
Date User Action Args
2018-08-26 14:25:51mark.dickinsonsetrecipients: + mark.dickinson
2018-08-26 14:25:50mark.dickinsonsetmessageid: <1535293550.9.0.56676864532.issue34508@psf.upfronthosting.co.za>
2018-08-26 14:25:50mark.dickinsonlinkissue34508 messages
2018-08-26 14:25:50mark.dickinsoncreate