Skip to content

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

Merged
gvanrossum merged 6 commits into
python:masterfrom
dacut:master
Sep 22, 2018
Merged

bpo-32117: Allow tuple unpacking in return and yield statements#4509
gvanrossum merged 6 commits into
python:masterfrom
dacut:master

Conversation

@dacut

@dacut dacut commented Nov 22, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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

dacut commented Nov 22, 2017

Copy link
Copy Markdown
Contributor Author

CLA signed and awaiting review.

@dacut

dacut commented Nov 29, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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?

Comment thread Lib/test/test_grammar.py
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
Copy Markdown
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
Copy Markdown
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

dacut commented Sep 16, 2018

Copy link
Copy Markdown
Contributor Author

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

@jChapman

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@brettcannon

Copy link
Copy Markdown
Member

@gvanrossum

Copy link
Copy Markdown
Member

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

@brettcannon

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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