From b7487dff302767bd2aed92df04d440f15c2eca14 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Thu, 6 Oct 2022 12:33:23 -0700 Subject: [PATCH] gh-86482: Document assignment expression need for ()s (GH-23291) Co-authored-by: Jelle Zijlstra (cherry picked from commit 2b5f1360ead9aa72ae00de59edfd6c229d13933f) Co-authored-by: Terry Jan Reedy --- Doc/reference/expressions.rst | 7 +++++++ .../2020-11-15-02-08-43.bpo-42316.LqdkWK.rst | 1 + 2 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-11-15-02-08-43.bpo-42316.LqdkWK.rst diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 0a9e7141d397a3..1e76b25f4880eb 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1748,6 +1748,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 00000000000000..ea997800bf076e --- /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.