summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2022-10-06 19:24:17 (GMT)
committerGitHub <noreply@github.com>2022-10-06 19:24:17 (GMT)
commit2b5f1360ead9aa72ae00de59edfd6c229d13933f (patch)
tree46a049fc44eed18ae7832d879557f7e74c23c937
parent6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b (diff)
downloadcpython-2b5f1360ead9aa72ae00de59edfd6c229d13933f.zip
cpython-2b5f1360ead9aa72ae00de59edfd6c229d13933f.tar.gz
cpython-2b5f1360ead9aa72ae00de59edfd6c229d13933f.tar.bz2
gh-86482: Document assignment expression need for ()s (#23291)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
-rw-r--r--Doc/reference/expressions.rst7
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2020-11-15-02-08-43.bpo-42316.LqdkWK.rst1
2 files changed, 8 insertions, 0 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index a6ca55d..a661e03 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -1766,6 +1766,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
index 0000000..ea99780
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-11-15-02-08-43.bpo-42316.LqdkWK.rst
@@ -0,0 +1 @@
+Document some places where an assignment expression needs parentheses.