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: Henk-Jaap Wagenaar, Jordan Chapman, dacut, gvanrossum, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-11-22 23:31 by dacut, last changed 2018-09-22 03:48 by Jordan Chapman. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4509 merged dacut, 2017-11-22 23:39
PR 9487 open Jordan Chapman, 2018-09-22 03:48
Messages (13)
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 (Henk-Jaap Wagenaar) * 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.
History
Date User Action Args
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:21Henk-Jaap Wagenaarsetnosy: + Henk-Jaap Wagenaar
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