]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111944: Add assignment expression parentheses requirements (#111977)
authorTerry Jan Reedy <tjreedy@udel.edu>
Mon, 13 Nov 2023 00:06:50 +0000 (19:06 -0500)
committerGitHub <noreply@github.com>
Mon, 13 Nov 2023 00:06:50 +0000 (19:06 -0500)
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.

Doc/reference/expressions.rst

index 88d4fca4e3267cc3b6db595af0c6f911b2e68b7f..14c2afa15ad7fb9e08b3ba7aed297bc99cf182ca 100644 (file)
@@ -1781,10 +1781,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.