]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-111944: Add assignment expression parentheses requirements (GH-111977)...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 13 Nov 2023 00:14:03 +0000 (01:14 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Nov 2023 00:14:03 +0000 (00:14 +0000)
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 9a2f25d374f027f6509484d66e1c7bba03977b99)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Doc/reference/expressions.rst

index 5cba4a6934f05b53f53d4cb9934a88b9fc02731a..9207fd3f3c02ee87ffb4c1dbc323b6cc1b547507 100644 (file)
@@ -1764,10 +1764,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.