[Python-Dev] Allow tuple unpacking in return and yield statements
David Cuthbert
dacut at kanga.org
Sat Nov 25 01:55:15 EST 2017
First time contributing back -- if I should be filing a PEP or something like that for this, please let me know.
Coming from https://bugs.python.org/issue32117, unparenthesized tuple unpacking is allowed in assignments:
rest = (4, 5, 6)
a = 1, 2, 3, *rest
but not in yield or return statements (these result in SyntaxErrors):
return 1, 2, 3, *rest
yield 1, 2, 3, *rest
The unpacking in assignments was enabled by a pre-3.2 commit that I haven't yet been able to track back to a discussion, but I suspect this asymmetry is unintentional. Here's the original commit:
https://github.com/python/cpython/commit/4905e80c3d2f6abb613d212f0313d1dfe09475dc
I've submitted a patch (CLA is signed and submitted, not yet processed), and Serihy said that since it changes the grammar I should have it reviewed here and have signoff by the BDFL.
While I haven't had a need for this myself, it was brought up by a user on StackOverflow (https://stackoverflow.com/questions/47272460/python-tuple-unpacking-in-return-statement/47326859).
Thanks!
Dave
More information about the Python-Dev
mailing list