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.

classification
Title: Tuple unpacking in return and yield statements
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jordan Chapman, cryvate, dacut, gvanrossum, miss-islington, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-11-22 23:31 by dacut, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4509 merged dacut, 2017-11-22 23:39
PR 9487 merged Jordan Chapman, 2018-09-22 03:48
PR 9721 merged serhiy.storchaka, 2018-10-05 17:52
PR 16994 merged python-dev, 2019-10-30 13:06
PR 19737 merged python-dev, 2020-04-27 18:01
Messages (17)
msg306761 - (view) Author: David Cuthbert (dacut) * Date: 2017-11-22 23:31
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

def h():
    rest = (4, 5, 6)
    yield 1, 2, 3, *rest

Looking at the original commit that enabled tuple unpacking in assignment statements:
https://github.com/python/cpython/commit/4905e80c3d2f6abb613d212f0313d1dfe09475dc

I don't believe this difference is intentional.

My GitHub repo incorporates a fix for this; I'll file a pull request momentarily.
msg306783 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-23 06:16
Since this changes the grammar, it should be first discussed on Python-Dev and approved by BDFL.
msg307257 - (view) Author: David Cuthbert (dacut) * Date: 2017-11-29 21:44
CLA processed, and BDFL has assented on python-dev. Serhiy, thoughts on next steps?
msg307264 - (view) Author: Henk-Jaap Wagenaar (cryvate) * Date: 2017-11-29 22:07
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.
msg307266 - (view) Author: David Cuthbert (dacut) * Date: 2017-11-29 22:20
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@
msg307267 - (view) Author: David Cuthbert (dacut) * Date: 2017-11-29 22:30
Oops, I wasn't looking broadly enough. This is also used in the augmented assignment statements syntax, e.g. a += 1, 2, 3
msg325327 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2018-09-14 06:09
Move to 3.8.
msg325421 - (view) Author: Jordan Chapman (Jordan Chapman) * Date: 2018-09-15 04:21
BFDL approval: https://mail.python.org/pipermail/python-dev/2017-November/150842.html
msg325459 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2018-09-15 22:34
Jordan, what's your GitHub account name? I hope you can check this out and make the changes I'm requesting on GitHub.
msg325460 - (view) Author: Jordan Chapman (Jordan Chapman) * Date: 2018-09-15 22:44
Here's my GitHub account: I'll make the changes and rebase as soon as I get home.
msg325461 - (view) Author: Jordan Chapman (Jordan Chapman) * Date: 2018-09-15 22:45
Sorry, I could have sworn that I pasted my link... https://github.com/jChapman
msg326063 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2018-09-22 01:31
New changeset fd97d1f1af910a6222ea12aec42c456b64f9aee4 by Guido van Rossum (David Cuthbert) in branch 'master':
bpo-32117: Allow tuple unpacking in return and yield statements (gh-4509)
https://github.com/python/cpython/commit/fd97d1f1af910a6222ea12aec42c456b64f9aee4
msg326064 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2018-09-22 01:34
Fixed by https://github.com/python/cpython/pull/4509.
msg326122 - (view) Author: miss-islington (miss-islington) Date: 2018-09-23 01:13
New changeset 8fabae3b00b2ccffd9f7bf4736734ae584ac5829 by Miss Islington (bot) (jChapman) in branch 'master':
bpo-32117: Iterable unpacking in return and yield documentation (GH-9487)
https://github.com/python/cpython/commit/8fabae3b00b2ccffd9f7bf4736734ae584ac5829
msg326823 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-01 20:25
assertEquals() is deprecated, use assertEqual() instead. This causes tests failure when run with -Werror.
msg327160 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-05 18:10
New changeset 4642d5f59828e774585e9895b538b24d71b9df8e by Serhiy Storchaka in branch 'master':
Use assertEqual() instead of assertEquals(). (GH-9721)
https://github.com/python/cpython/commit/4642d5f59828e774585e9895b538b24d71b9df8e
msg368161 - (view) Author: miss-islington (miss-islington) Date: 2020-05-05 14:50
New changeset 627f7012353411590434a7d5777ddcbcc8d97fcd by Javier Buzzi in branch 'master':
bpo-32117: Updated Simpsons names in docs (GH-19737)
https://github.com/python/cpython/commit/627f7012353411590434a7d5777ddcbcc8d97fcd
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76298
2020-05-05 14:50:03miss-islingtonsetmessages: + msg368161
2020-04-27 18:01:00python-devsetnosy: + python-dev

pull_requests: + pull_request19059
2019-10-30 13:06:24python-devsetpull_requests: + pull_request16520
2018-10-05 18:18:03serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
2018-10-05 18:10:02serhiy.storchakasetmessages: + msg327160
2018-10-05 17:52:10serhiy.storchakasetstage: needs patch -> patch review
pull_requests: + pull_request9105
2018-10-01 20:25:59serhiy.storchakasetstatus: closed -> open

messages: + msg326823
stage: resolved -> needs patch
2018-09-23 01:13:15miss-islingtonsetnosy: + miss-islington
messages: + msg326122
2018-09-22 03:48:49Jordan Chapmansetpull_requests: + pull_request8897
2018-09-22 01:34:30gvanrossumsetstatus: open -> closed
resolution: fixed
messages: + msg326064

stage: patch review -> resolved
2018-09-22 01:31:20gvanrossumsetmessages: + msg326063
2018-09-15 22:45:15Jordan Chapmansetmessages: + msg325461
2018-09-15 22:44:11Jordan Chapmansetmessages: + msg325460
2018-09-15 22:34:31gvanrossumsetmessages: + msg325459
2018-09-15 04:21:41Jordan Chapmansetnosy: + Jordan Chapman
messages: + msg325421
2018-09-14 06:09:44gvanrossumsetnosy: + gvanrossum

messages: + msg325327
versions: + Python 3.8, - Python 3.7
2018-05-09 09:54:55serhiy.storchakalinkissue32626 superseder
2017-11-29 22:30:57dacutsetmessages: + msg307267
2017-11-29 22:20:32dacutsetmessages: + msg307266
2017-11-29 22:07:21cryvatesetnosy: + cryvate
messages: + msg307264
2017-11-29 21:44:55dacutsetmessages: + msg307257
2017-11-23 06:17:21serhiy.storchakasetversions: + Python 3.7, - Python 3.4, Python 3.5, Python 3.6
2017-11-23 06:16:52serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg306783
2017-11-22 23:39:10dacutsetkeywords: + patch
stage: patch review
pull_requests: + pull_request4446
2017-11-22 23:31:49dacutcreate