From 3b7e308a24fdaf24e45ad3ce980e52a2778b548e Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 13 Nov 2023 01:17:54 +0100 Subject: [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 9a2f25d374f027f6509484d66e1c7bba03977b99) Co-authored-by: Terry Jan Reedy --- Doc/reference/expressions.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index cac7ae7..e29d3a0 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1774,10 +1774,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. -- cgit v0.12