[3.12] gh-111944: Add assignment expression parentheses requirements (GH-111977) (#112010)

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 9a2f25d374)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2023-11-13 01:17:54 +01:00 committed by GitHub
parent 378a96e361
commit 3b7e308a24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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