New submission from Mark Dickinson <dicki...@gmail.com>:
[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] ---------- components: Interpreter Core messages: 324118 nosy: mark.dickinson priority: normal severity: normal status: open title: return of non-parenthesized star-unpacking expression a SyntaxError type: enhancement versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34508> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com