Skip to content

Commit b64afbc

Browse files
[3.11] gh-111944: Add assignment expression parentheses requirements (GH-111977) (#112011)
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 <[email protected]>
1 parent aa3232d commit b64afbc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Doc/reference/expressions.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,10 +1764,11 @@ Or, when processing a file stream in chunks:
17641764
while chunk := file.read(9000):
17651765
process(chunk)
17661766
1767-
Assignment expressions must be surrounded by parentheses when used
1768-
as sub-expressions in slicing, conditional, lambda,
1769-
keyword-argument, and comprehension-if expressions
1770-
and in ``assert`` and ``with`` statements.
1767+
Assignment expressions must be surrounded by parentheses when
1768+
used as expression statements and when used as sub-expressions in
1769+
slicing, conditional, lambda,
1770+
keyword-argument, and comprehension-if expressions and
1771+
in ``assert``, ``with``, and ``assignment`` statements.
17711772
In all other places where they can be used, parentheses are not required,
17721773
including in ``if`` and ``while`` statements.
17731774

0 commit comments

Comments
 (0)