Skip to content

bpo-32117: Allow tuple unpacking in return and yield statements #4509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 22, 2018
Merged

bpo-32117: Allow tuple unpacking in return and yield statements #4509

merged 6 commits into from
Sep 22, 2018

Conversation

dacut
Copy link
Contributor

@dacut dacut commented Nov 22, 2017

This is a fix for issue 32117:

This stems from a query on StackOverflow.

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:
4905e80

I don't believe this difference is intentional.

https://bugs.python.org/issue32117

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@dacut dacut changed the title Allow tuple unpacking in return and yield statements Allow tuple unpacking in return and yield statements bpo-32117 Nov 22, 2017
@dacut
Copy link
Contributor Author

dacut commented Nov 22, 2017

CLA signed and awaiting review.

@dacut
Copy link
Contributor Author

dacut commented Nov 29, 2017

CLA reviewed and approved.

@serhiy-storchaka serhiy-storchaka changed the title Allow tuple unpacking in return and yield statements bpo-32117 bpo-32117: Allow tuple unpacking in return and yield statements Mar 26, 2018
@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Mar 26, 2018
@gvanrossum
Copy link
Member

I'm going to close and reopen to cause Travis-CI and AppVeyor to rerun the tests.

@gvanrossum gvanrossum closed this Sep 14, 2018
@gvanrossum gvanrossum reopened this Sep 14, 2018
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming @dacut is no longer interested in this PR. Jordan Chapman, can you add the test I requested and rebase, then push?

@@ -828,6 +834,8 @@ def g(): f((yield 1))
def g(): f((yield 1), 1)
def g(): f((yield from ()))
def g(): f((yield from ()), 1)
# Do not require parenthesis for tuple unpacking
def g(): rest = 4, 5, 6; yield 1, 2, 3, *rest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add another test here to validate that this works, e.g. self.assertEqual(list(g()), [(1, 2, 3, 4, 5, 6)]).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was tempted to do self.assertEqual(*g(), (1, 2, 3, 4, 5, 6)), but I think we're testing enough unpacking

@dacut
Copy link
Contributor Author

dacut commented Sep 16, 2018

I am. :-) I'll add that test if Jordan doesn't beat me to it.

@jChapman
Copy link
Contributor

I've added the test to my fork (https://github.com/jChapman/cpython) and rebased, but I don't have the ability to modify this pull request, so I am unsure how to proceed.

@gvanrossum
Copy link
Member

Also, I checked that CLA from @jChapman was received so I'll change those labels. I'll probably wait a day before merging, in case another core dev wants to have a look and/or say.

@jChapman
Copy link
Contributor

@gvanrossum Reminder to complete merge (it has now been 4 days)

@brettcannon
Copy link
Member

@gvanrossum
Copy link
Member

@brettcannon What's that trello.com link? I get "Card not found".

@brettcannon
Copy link
Member

I touched up the news entry slightly (made sure to thank @dacut and @jChapman 😄 ). If @gvanrossum doesn't merge this by the time I do my next sweep through my Python TODO list then I will.

@brettcannon
Copy link
Member

@gvanrossum the Trello card is for my private board to keep track of my TODO entries; didn't realize it left a comment. :/

@gvanrossum
Copy link
Member

I see no reason to hold this up. Thanks @dacut for the fix and @jChapman for pinging this!

@gvanrossum gvanrossum merged commit fd97d1f into python:master Sep 22, 2018
@gvanrossum
Copy link
Member

Well, I think the news entry should say "parentheses" instead of "parenthesis", and we need an entry in whatsnew.rst, but that can be done in a followup PR (@dacut and @jChapman, if one of you would be so kind?).

Also it's ridiculous what GitHub did to my commit message, but too late to fix now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants