Skip to content

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

Merged
pablogsal merged 3 commits into
python:masterfrom
isidentical:bpo-40715
May 21, 2020
Merged

bpo-40715: Reject dict unpacking on dict comprehensions#20292
pablogsal merged 3 commits into
python:masterfrom
isidentical:bpo-40715

Conversation

@isidentical
Copy link
Copy Markdown
Member

@isidentical isidentical commented May 21, 2020

@lysnikolaou
Copy link
Copy Markdown
Member

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?

@pablogsal
Copy link
Copy Markdown
Member

@isidentical You need to rebase and regenerate the parser

@lysnikolaou
Copy link
Copy Markdown
Member

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

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

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.

Comment thread Grammar/python.gram Outdated
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Copy link
Copy Markdown
Member

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

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