You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tuple unpacking in return and yield statements #76298
New changeset fd97d1f by Guido van Rossum (David Cuthbert) in branch 'master': bpo-32117: Allow tuple unpacking in return and yield statements (gh-4509) fd97d1f
New changeset 8fabae3 by Miss Islington (bot) (jChapman) in branch 'master': bpo-32117: Iterable unpacking in return and yield documentation (GH-9487) 8fabae3
Activity
dacut commentedon Nov 22, 2017
This stems from a query on StackOverflow: https://stackoverflow.com/questions/47272460/python-tuple-unpacking-in-return-statement/
Specifically, the following syntax is allowed:
def f():
rest = (4, 5, 6)
t = 1, 2, 3, *rest
While the following result in SyntaxError:
def g():
rest = (4, 5, 6)
return 1, 2, 3, *rest
Looking at the original commit that enabled tuple unpacking in assignment statements:
4905e80
I don't believe this difference is intentional.
My GitHub repo incorporates a fix for this; I'll file a pull request momentarily.
serhiy-storchaka commentedon Nov 23, 2017
Since this changes the grammar, it should be first discussed on Python-Dev and approved by BDFL.
dacut commentedon Nov 29, 2017
CLA processed, and BDFL has assented on python-dev. Serhiy, thoughts on next steps?
Cryvate commentedon Nov 29, 2017
I think the language spec needs updating as well? In particular in
https://docs.python.org/3/reference/simple_stmts.html#the-return-statement
it seems expression_list should be replaced by starred_list.
dacut commentedon Nov 29, 2017
Hm... that leaves the only production for expression_list as:
subscription ::= primary "[" expression_list "]"
And I'm not sure that this shouldn't also be replaced by starred_list. It's not accepted today, though:
In [6]: a[1,(4, 5, 6)]
File "<ipython-input-6-ba56159162e9>", line 1
a[1,(4, 5, 6)]
^
SyntaxError: invalid syntax
I will ask about this again on python-dev@
dacut commentedon Nov 29, 2017
Oops, I wasn't looking broadly enough. This is also used in the augmented assignment statements syntax, e.g. a += 1, 2, 3
gvanrossum commentedon Sep 14, 2018
Move to 3.8.
jChapman commentedon Sep 15, 2018
BFDL approval: https://mail.python.org/pipermail/python-dev/2017-November/150842.html
gvanrossum commentedon Sep 15, 2018
Jordan, what's your GitHub account name? I hope you can check this out and make the changes I'm requesting on GitHub.
jChapman commentedon Sep 15, 2018
Here's my GitHub account: I'll make the changes and rebase as soon as I get home.
jChapman commentedon Sep 15, 2018
Sorry, I could have sworn that I pasted my link... https://github.com/jChapman
gvanrossum commentedon Sep 22, 2018
New changeset fd97d1f by Guido van Rossum (David Cuthbert) in branch 'master':
bpo-32117: Allow tuple unpacking in return and yield statements (gh-4509)
fd97d1f
gvanrossum commentedon Sep 22, 2018
Fixed by #4509.
miss-islington commentedon Sep 23, 2018
New changeset 8fabae3 by Miss Islington (bot) (jChapman) in branch 'master':
bpo-32117: Iterable unpacking in return and yield documentation (GH-9487)
8fabae3
serhiy-storchaka commentedon Oct 1, 2018
assertEquals() is deprecated, use assertEqual() instead. This causes tests failure when run with -Werror.
serhiy-storchaka commentedon Oct 5, 2018
New changeset 4642d5f by Serhiy Storchaka in branch 'master':
Use assertEqual() instead of assertEquals(). (GH-9721)
4642d5f
miss-islington commentedon May 5, 2020
New changeset 627f701 by Javier Buzzi in branch 'master':
bpo-32117: Updated Simpsons names in docs (GH-19737)
627f701
[syntax-errors] Tuple unpacking in `return` and `yield` before 3.8
[syntax-errors] Tuple unpacking in `return` and `yield` before 3.8
[syntax-errors] Tuple unpacking in `return` and `yield` before Python…
[syntax-errors] Tuple unpacking in `return` and `yield` before Python…