Skip to content
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

gh-86482: Document assignment expression need for ()s #23291

Merged
merged 8 commits into from Oct 6, 2022

Conversation

terryjreedy
Copy link
Member

@terryjreedy terryjreedy commented Nov 15, 2020

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.

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.
@terryjreedy terryjreedy added docs Documentation in the Doc dir needs backport to 3.8 only security fixes needs backport to 3.9 only security fixes labels Nov 15, 2020
@terryjreedy terryjreedy self-assigned this Nov 15, 2020
@lysnikolaou
Copy link
Contributor

This PR probably needs to be updated to reflect the recent changes introduced in #23317 and #23319. Sorry @terryjreedy!

@terryjreedy
Copy link
Member Author

These are changes I hoped to be able to make ;-). I will add the new in 3.10 item for indexes.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Dec 18, 2020
@ambv ambv removed the needs backport to 3.8 only security fixes label May 4, 2021
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terryjreedy are you still interested in landing this? A few older comments were never applied.

Doc/reference/expressions.rst Outdated Show resolved Hide resolved
Doc/reference/expressions.rst Outdated Show resolved Hide resolved
@terryjreedy terryjreedy removed their assignment Apr 6, 2022
@terryjreedy
Copy link
Member Author

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

I have been recently de-authorized from merging anything

Pablo had turned off merges for everyone during the 3.11.0a7 release, but merges are allowed now again.

@JelleZijlstra JelleZijlstra self-assigned this Apr 6, 2022
@serhiy-storchaka serhiy-storchaka added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes and removed needs backport to 3.9 only security fixes labels May 20, 2022
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jul 31, 2022
Doc/reference/expressions.rst Outdated Show resolved Hide resolved
Doc/reference/expressions.rst Outdated Show resolved Hide resolved
Doc/reference/expressions.rst Outdated Show resolved Hide resolved
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me now. I'll merge it in a few days unless other people on the PR have more feedback.

@gvanrossum
Copy link
Member

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).

@@ -1766,6 +1766,12 @@ Or, when processing a file stream in chunks:
while chunk := file.read(9000):
process(chunk)

Assignment expressions must be surrounded by parentheses when used
as sub-expressions in slicing, conditional, lambda,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! I mixed up indexes/slices. Sorry!

@JelleZijlstra JelleZijlstra merged commit 2b5f136 into python:main Oct 6, 2022
@miss-islington
Copy link
Contributor

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

GH-97986 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Oct 6, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 6, 2022
…-23291)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@bedevere-bot
Copy link

GH-97987 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Oct 6, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 6, 2022
…-23291)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@Brando753 Brando753 mannequin mentioned this pull request Oct 6, 2022
miss-islington added a commit that referenced this pull request Oct 6, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington added a commit that referenced this pull request Oct 6, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
carljm added a commit to carljm/cpython that referenced this pull request Oct 6, 2022
* main:
  fixes pythongh-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)
carljm added a commit to carljm/cpython that referenced this pull request Oct 8, 2022
* 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)
  fixes pythongh-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)
mpage pushed a commit to mpage/cpython that referenced this pull request Oct 11, 2022
…3291)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
pablogsal pushed a commit that referenced this pull request Oct 22, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@terryjreedy terryjreedy deleted the walrus branch December 17, 2023 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants