8000 [3.12] gh-111944: Add assignment expression parentheses requirements (GH-111977) by miss-islington · Pull Request #112010 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.12] gh-111944: Add assignment expression parentheses requirements (GH-111977) #112010

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

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-111944: Add assignment expression parentheses requirements (GH-111977
)

gh-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 <tjreedy@udel.edu>
  • Loading branch information
terryjreedy authored and miss-islington committed Nov 13, 2023
commit 1d450b16f78066ff5426c0c6133260dfcd053e38
9 changes: 5 additions & 4 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1774,10 +1774,11 @@ 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,
keyword-argument, and comprehension-if expressions
and in ``assert`` and ``with`` statements.
Assignment expressions must be surrounded by parentheses when
used as expression statements and when used as sub-expressions in
slicing, conditional, lambda,
keyword-argument, and comprehension-if expressions and
in ``assert``, ``with``, and ``assignment`` statements.
In all other places where they can be used, parentheses are not required,
including in ``if`` and ``while`` statements.

Expand Down
0