8000 gh-111944: Add assignment expression parentheses requirements (#111977) · python/cpython@9a2f25d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a2f25d

Browse files
authored
gh-111944: Add assignment expression parentheses requirements (#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.
1 parent d7cef7b commit 9a2f25d

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
@@ -1781,10 +1781,11 @@ Or, when processing a file stream in chunks:
17811781
while chunk := file.read(9000):
17821782
process(chunk)
17831783
1784-
Assignment expressions must be surrounded by parentheses when used
1785-
as sub-expressions in slicing, conditional, lambda,
1786-
keyword-argument, and comprehension-if expressions
1787-
and in ``assert`` and ``with`` statements.
1784+
Assignment expressions must be surrounded by parentheses when
1785+
used as expression statements and when used as sub-expressions in
1786+
slicing, conditional, lambda,
1787+
keyword-argument, and comprehension-if expressions and
1788+
in ``assert``, ``with``, and ``assignment`` statements.
17881789
In all other places where they can be used, parentheses are not required,
17891790
including in ``if`` and ``while`` statements.
17901791

0 commit comments

Comments
 (0)
0