]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-86482: Document assignment expression need for ()s (GH-23291)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 6 Oct 2022 19:32:39 +0000 (12:32 -0700)
committerGitHub <noreply@github.com>
Thu, 6 Oct 2022 19:32:39 +0000 (12:32 -0700)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b5f1360ead9aa72ae00de59edfd6c229d13933f)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Doc/reference/expressions.rst
Misc/NEWS.d/next/Core and Builtins/2020-11-15-02-08-43.bpo-42316.LqdkWK.rst [new file with mode: 0644]

index 6d23e473cdcd41dc1eb024a6ac0f233e99e70a7a..fd43e6c161f78936046f14f7e6f2ca4abf499ab3 100644 (file)
@@ -1755,6 +1755,13 @@ 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.
+In all other places where they can be used, parentheses are not required,
+including in ``if`` and ``while`` statements.
+
 .. versionadded:: 3.8
    See :pep:`572` for more details about assignment expressions.
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-11-15-02-08-43.bpo-42316.LqdkWK.rst b/Misc/NEWS.d/next/Core and Builtins/2020-11-15-02-08-43.bpo-42316.LqdkWK.rst
new file mode 100644 (file)
index 0000000..ea99780
--- /dev/null
@@ -0,0 +1 @@
+Document some places where an assignment expression needs parentheses.