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
Allow for
's target expression to be starred
#2879
Conversation
Thanks, some minor feedback.
Also, I noticed that [x for x in *a, *b]
isn't allowed. Just curious, do you know why that is?
@@ -62,6 +62,7 @@ | |||
] | |||
|
|||
PY310_CASES: List[str] = [ | |||
"starred_for_target", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be 310-specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the PEP 617 was opt-out in 3.9, the given examples are rejected by the official AST when the user starts the python interpreter with -Xoldparser
. It is why I've added tests to 3.10 group.
@JelleZijlstra this seems to be something that was introduced during the PEG parser merge, but there is no official reference in anywhere beside the grammar. I have no knowledge on the comprehensions, but perhaps @pablogsal can shed more light in that. |
Hummm, maybe I am misunderstanding this, but this syntax has never been allowed:
|
This is In the same spirit as
|
My thinking process was just "hey, I didn't know this was allowed, I wonder where else it could be allowed". But it does make sense that we're a bit stricter in comprehensions than in standalone for loops. Thanks for the extra information! |
@pablogsal no, I have meant the regular
The git bisect tells me that this behavior initially got introduced in the PEP 617 merge. Since with 3.9/3.10 this is now supported, what we wonder is why these two are inconsistent. |
Ah, sorry, I misunderstood your comment. Yes, that was introduced on PEP 617 merge but I am not actually sure that was on purpose as I cannot find any previous discussion. Maybe we need to revert that :( |
It might be a bit too late, no? (it was part of both 3.9/3.10 stable). But yea, let's create a bpo ticket to discuss further. |
It may be, but if we treat it like a bug, you are technically not allowed to rely on the bug :) |
Let's hold off on merging this until the BPO is resolved. If CPython's decision is to remove the syntax, I think it makes sense for Black to disallow it too. |
Has been documented in python/cpython#31481. Thanks for fixing this Batuhan!
Fixes #2878