Skip to content

Commit 4aa2ebc

Browse files
gh-86482: Document assignment expression need for ()s (GH-23291)
Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 2b5f136) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 6057030 commit 4aa2ebc

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Doc/reference/expressions.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,13 @@ Or, when processing a file stream in chunks:
17551755
while chunk := file.read(9000):
17561756
process(chunk)
17571757
1758+
Assignment expressions must be surrounded by parentheses when used
1759+
as sub-expressions in slicing, conditional, lambda,
1760+
keyword-argument, and comprehension-if expressions
1761+
and in ``assert`` and ``with`` statements.
1762+
In all other places where they can be used, parentheses are not required,
1763+
including in ``if`` and ``while`` statements.
1764+
17581765
.. versionadded:: 3.8
17591766
See :pep:`572` for more details about assignment expressions.
17601767

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document some places where an assignment expression needs parentheses.

0 commit comments

Comments
 (0)