Skip to content

Commit cc10a8e

Browse files
miss-islingtonterryjreedy
authored andcommitted
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 a3df8d7 commit cc10a8e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Doc/reference/expressions.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,13 @@ Or, when processing a file stream in chunks:
17511751
while chunk := file.read(9000):
17521752
process(chunk)
17531753
1754+
Assignment expressions must be surrounded by parentheses when used
1755+
as sub-expressions in slicing, conditional, lambda,
1756+
keyword-argument, and comprehension-if expressions
1757+
and in ``assert`` and ``with`` statements.
1758+
In all other places where they can be used, parentheses are not required,
1759+
including in ``if`` and ``while`` statements.
1760+
17541761
.. versionadded:: 3.8
17551762
See :pep:`572` for more details about assignment expressions.
17561763

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)