Uh oh!
There was an error while loading. Please reload this page.
gh-86482: Document assignment expression need for ()s - #23291
Conversation
The list should cover most places where an assignment sub-expression must be wrapped in parentheses. Judging from the statement docs, only a couple of statements do not require that they be wrapped.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
lysnikolaou
commented
Nov 16, 2020
This PR probably needs to be updated to reflect the recent changes introduced in #23317 and #23319. Sorry @terryjreedy! |
terryjreedy
commented
Nov 17, 2020
These are changes I hoped to be able to make ;-). I will add the new in 3.10 item for indexes. |
This PR is stale because it has been open for 30 days with no activity. |
JelleZijlstra
left a comment
There was a problem hiding this comment.
@terryjreedy are you still interested in landing this? A few older comments were never applied.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
terryjreedy
commented
Apr 6, 2022
I somehow missed finishing this and would like it updated and merged. The doc is needed; someone just posted code to pydev that was missing required ()s. However, I just discovered that I have been recently de-authorized from merging anything. Jelle, you have been doing great with doc patches, so it would be fine with me if you finished this without waiting for that problem to be fixed. |
JelleZijlstra
commented
Apr 6, 2022
Pablo had turned off merges for everyone during the 3.11.0a7 release, but merges are allowed now again. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
JelleZijlstra
left a comment
There was a problem hiding this comment.
This looks good to me now. I'll merge it in a few days unless other people on the PR have more feedback.
Uh oh!
There was an error while loading. Please reload this page.
gvanrossum
commented
Oct 3, 2022
I'm fine with documenting this more precisely, and the wording here looks fine. However, I don't have the time to review the facts -- I hope that Lysandros and Jelle can make sure that the claim made in the text is true (or as close to true as reasonable without spelling out the entire grammar). |
| process(chunk) | ||
| Assignment expressions must be surrounded by parentheses when used | ||
| as sub-expressions in slicing, conditional, lambda, |
There was a problem hiding this comment.
Unparenthesized assignment expressions in slices were implemented in #23317, so they are allowed since 3.10. Also, assignment expression need to parenthesized in assert and with statements.
There was a problem hiding this comment.
Unparenthesized walruses are allowed in index expressions but not slices. This is current 3.12:
>>> x[y:=3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x[y:=3:z:=4]
File "<stdin>", line 1
x[y:=3:z:=4]
^
SyntaxError: invalid syntax
There was a problem hiding this comment.
Correct! I mixed up indexes/slices. Sorry!
Uh oh!
There was an error while loading. Please reload this page.
miss-islington
commented
Oct 6, 2022
Thanks @terryjreedy for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
bedevere-bot
commented
Oct 6, 2022
GH-97986 is a backport of this pull request to the 3.11 branch. |
bedevere-bot
commented
Oct 6, 2022
GH-97987 is a backport of this pull request to the 3.10 branch. |
* main: fixespythongh-96078: os.sched_yield release the GIL while calling sched_yield(2). (pythongh-97965) pythongh-65961: Do not rely solely on `__cached__` (pythonGH-97990) pythongh-97850: Remove the open issues section from the import reference (python#97935) Docs: pin sphinx-lint (pythonGH-97992) pythongh-94590: add signatures to operator itemgetter, attrgetter, methodcaller (python#94591) Add Pynche's move to the What's new in 3.11 (python#97974) pythongh-97781: Apply changes from importlib_metadata 5. (pythonGH-97785) pythongh-86482: Document assignment expression need for ()s (python#23291) pythongh-97943: PyFunction_GetAnnotations should return a borrowed reference. (python#97949) pythongh-94808: Coverage: Test that maximum indentation level is handled (python#95926)
* main: pythonGH-97002: Prevent `_PyInterpreterFrame`s from backing more than one `PyFrameObject` (pythonGH-97996) pythongh-97973: Return all necessary information from the tokenizer (pythonGH-97984) fixespythongh-96078: os.sched_yield release the GIL while calling sched_yield(2). (pythongh-97965) pythongh-65961: Do not rely solely on `__cached__` (pythonGH-97990) pythongh-97850: Remove the open issues section from the import reference (python#97935) Docs: pin sphinx-lint (pythonGH-97992) pythongh-94590: add signatures to operator itemgetter, attrgetter, methodcaller (python#94591) Add Pynche's move to the What's new in 3.11 (python#97974) pythongh-97781: Apply changes from importlib_metadata 5. (pythonGH-97785) pythongh-86482: Document assignment expression need for ()s (python#23291) pythongh-97943: PyFunction_GetAnnotations should return a borrowed reference. (python#97949)
…3291) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
The list should cover most places where an assignment sub-expression
must be wrapped in parentheses. Judging from the statement docs,
only a couple of statements do not require that they be wrapped.