-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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 unparenthesized walrus in set comprehensions #86547
Comments
Since unparenthesized walruses are allowed in list comprehensions and in generator expressions, should we maybe allow them in set comprehensions as well? |
Yeah, I suppose the comprehensions should all have the same syntax inside their various brackets. |
Apparently we currently don't allow walruses in set literals either: >>> {y := 4, 4**2, 3**3}
File "<stdin>", line 1
{y := 4, 4**2, 3**3}
^
SyntaxError: invalid syntax But they should be allowed as well per PEP-572 (as the pep mentions all comprehensions): There is one special case: an assignment expression occurring in a list, set or dict comprehension or in a generator expression (below collectively referred to as "comprehensions") binds the target in ... |
The only question left is that if we should allow this on dict literals and dict comprehensions as well (because these constructs have a ":" in the middle that can be noisy if there are walrus, the answer isn't immediately obvious to me). |
FWIW, unparenthesized walruses are still disallowed in dictcomps and to be honest, I'm not sure if we should allow them or not. I feel that allowing too many colons there would be too noisy. {a:='a': b:=1} doesn't really look too beautiful. |
Not in anything dict please. Nagging question — is there sufficient difference between {x := y} and {x: y} ? |
While {(a:='a'): (b:=1)} looks somewhat cleaner to me. |
I think there is enough distinction, yes. It will also be a bit odd if is allowed in list and list comps but not set and set comps |
Okay. |
Let’s make sure this is all written up in whatsnew. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: