Skip to content
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

bpo-40715: Reject dict unpacking on dict comprehensions #20292

Merged
merged 3 commits into from
May 21, 2020

Conversation

isidentical
Copy link
Sponsor Member

@isidentical isidentical commented May 21, 2020

@lysnikolaou
Copy link
Contributor

Suggestion for being consistent with things like starred_expression (feel free to ignore): Rename kvpair to double_starred_kvpair and simple_kvpair to plain kvpair. What do you think?

@lysnikolaou lysnikolaou added the needs backport to 3.9 only security fixes label May 21, 2020
@pablogsal
Copy link
Member

@isidentical You need to rebase and regenerate the parser

@lysnikolaou
Copy link
Contributor

lysnikolaou commented May 21, 2020

Also, if we want to be completely compatible with the old parser, the error caret should point to the opening brace:

╰─ cat t.py
{**{} for a in [1]}
╰─ ./python.exe -X oldparser t.py
  File "/Users/lysnikolaou/Repositories/cpython/t.py", line 1
    {**{} for a in [1]}
    ^
SyntaxError: dict unpacking cannot be used in dict comprehension

@isidentical
Copy link
Sponsor Member Author

Also, if we want to be completely compatible with the old parser, the error caret should point to the opening brace:

I thought it should be same with single starred expressions

 $ python t.py
  File "t.py", line 1
    [*[] for a in b]
     ^
SyntaxError: iterable unpacking cannot be used in comprehension

@lysnikolaou
Copy link
Contributor

Also, if we want to be completely compatible with the old parser, the error caret should point to the opening brace:

I thought it should be same with single starred expressions

 $ python t.py
  File "t.py", line 1
    [*[] for a in b]
     ^
SyntaxError: iterable unpacking cannot be used in comprehension

Yup, I find that kind of weird as well!

@pablogsal
Copy link
Member

pablogsal commented May 21, 2020

Also, if we want to be completely compatible with the old parser, the error caret should point to the opening brace:

Yeah, I think the old parser is the one should point to the **, but I don't think we need to make them match. I personally prefer that it points to the invalid token: the ** which is also consistent with starred expressions.

@lysnikolaou
Copy link
Contributor

Also, if we want to be completely compatible with the old parser, the error caret should point to the opening brace:

Yeah, I think the old parser is the one should point to the **, but I don't think we need to make them match. I personally prefer that it points to the invalid token: the ** which is also consistent with starred expressions.

If we've got no problem with showing to another token than the one the old parsers shows to, then no doubt, the '**' is the right one.

Grammar/python.gram Outdated Show resolved Hide resolved
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Copy link
Contributor

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@pablogsal pablogsal merged commit b8a65ec into python:master May 21, 2020
@miss-islington
Copy link
Contributor

Thanks @isidentical for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 21, 2020
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
(cherry picked from commit b8a65ec)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label May 21, 2020
@bedevere-bot
Copy link

GH-20303 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit that referenced this pull request May 21, 2020
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
(cherry picked from commit b8a65ec)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
arturoescaip pushed a commit to arturoescaip/cpython that referenced this pull request May 24, 2020
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants