-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Document better assignment expression parentheses requirements #111944
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
Comments
@terryjreedy I don't think the |
Top level assignment expressions work when parenthesized.
According to the expression doc According to the PEP, the behavior is intended, with the parenthesized form discouraged. See the first example under exceptional cases. So it seems that the doc should be fixed unless it is intended that the discouraged form not be documented. But I believe this would be unusual. To support a feature addition, argue against the PEP's prohibition rationale. |
Bug is for the doc not including 'top level code' in the list of places where parentheses are required. This list is characterized as all-inclusive by saying 'not needed' everywhere else. |
I'm sorry, I might not have made myself clear. I understand all that. I agree that the doc should be improved to include that top-level walruses need parentheses. But that should probably be a different issue. What I would like to do with this one, is start a discussion on whether we should lift that restriction. The PEP says:
I agree with the concept of "There should be one way to do it", but I would think that, in the context of a REPL, assignment statements and assignment expressions do two slightly different things. And I'm asking whether others agree so that this can be lifted, since it's also a very easy change to implement on the parser side. |
I am not in favor of lifting the restriction. I don’t want there to be two top level forms of assignment. |
What if it could only be enabled with an I'm asking because I generally agree with the sentiment. It's only in the context of a REPL, where I think this could be a slight improvement. |
That would only confuse users — what’s valid in one context wouldn’t be valid in another context. |
I agree -- I think we should keep the REPL consistent with Python in other contexts, wherever possible |
I don't think there's much chance of this succeeding, but if you want to pursue it you should open up a discussion on https://discuss.python.org/c/ideas/6 |
Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors.
I labelled as I did because the code and doc issues are not independent. If we change 'main' to allow |
There are two separately mentioned parenthesis requirements in the PEP missing from the Reference manual: |
…ythonGH-111977) pythongh-111944: Clarify where assignment expressions require ()s Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors. (cherry picked from commit 9a2f25d) Co-authored-by: Terry Jan Reedy <[email protected]>
…ythonGH-111977) pythongh-111944: Clarify where assignment expressions require ()s Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors. (cherry picked from commit 9a2f25d) Co-authored-by: Terry Jan Reedy <[email protected]>
…H-111977) (#112011) Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors. (cherry picked from commit 9a2f25d) Co-authored-by: Terry Jan Reedy <[email protected]>
…H-111977) (#112010) Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors. (cherry picked from commit 9a2f25d) Co-authored-by: Terry Jan Reedy <[email protected]>
Since there's consensus that this isn't something we want to support, I won't pursue this further. Thanks folks for your input and @terryjreedy for fixing the docs issue. |
…ython#111977) pythongh-111944: Clarify where assignment expressions require ()s Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors.
…ython#111977) pythongh-111944: Clarify where assignment expressions require ()s Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors.
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
Should we maybe thinks about allowing unparenthesized top-level assignment expressions. It came up on ipython/ipython#14214 that people would like to have something like that, especially in REPLs, in order to be able to assign a value to a variable and have it be displayed afterwards. I played around with the parser a bit and the change to allow this is very straight-forward.
We could also discuss adding it behind a flag or only enable it on the REPL.
Behavior on main:
New behavior:
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: