From ff66b334abf488a56f75ad59f1dc48787d2f624d Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 15 Nov 2020 02:38:11 -0500 Subject: [PATCH 1/6] bpo-42316: Document assignment expression need for ()s The list should cover most places where an assignment sub-expression must be wrapped in parentheses. Judging from the statement docs, only a couple of statements do not require that they be wrapped. --- Doc/reference/expressions.rst | 5 +++++ .../2020-11-15-02-08-43.bpo-42316.LqdkWK.rst | 1 + 2 files changed, 6 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 8ac626444843d2..7adb601eed62bc 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1687,6 +1687,11 @@ Or, when processing a file stream in chunks: while chunk := file.read(9000): process(chunk) +Assignment expressions must surrounded by parentheses when used +as sub-expressions in subscript, slicing, conditional, lambda, +keyword-argument, generator, and comprehension-if expressions. They +can only be used as is in if and while statements and in decorators. + .. 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. From 09653d783ea2bef0ea40832e8bce8ee62d4a6c2c Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 15 Nov 2020 02:41:55 -0500 Subject: [PATCH 2/6] Add 'be' --- Doc/reference/expressions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 7adb601eed62bc..c958e7ab719fc4 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1687,7 +1687,7 @@ Or, when processing a file stream in chunks: while chunk := file.read(9000): process(chunk) -Assignment expressions must surrounded by parentheses when used +Assignment expressions must be surrounded by parentheses when used as sub-expressions in subscript, slicing, conditional, lambda, keyword-argument, generator, and comprehension-if expressions. They can only be used as is in if and while statements and in decorators. From 4d0a933e94c28d60b973766b340f48e54fb38d4b Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 3 Oct 2022 13:50:53 -0700 Subject: [PATCH 3/6] Apply suggestions from code review --- Doc/reference/expressions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 55f588e1159065..0c1cb0c7b08329 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1767,9 +1767,9 @@ Or, when processing a file stream in chunks: process(chunk) Assignment expressions must be surrounded by parentheses when used -as sub-expressions in subscript, slicing, conditional, lambda, -keyword-argument, generator, and comprehension-if expressions. They -can only be used as is in if and while statements and in decorators. +as sub-expressions in slicing, conditional, lambda, +keyword-argument, and comprehension-if expressions. They +can be used unparenthesized in all other places, including ``if`` and ``while`` statements. .. versionadded:: 3.8 See :pep:`572` for more details about assignment expressions. From ae4788e95b822e74d349a87200539e794ce82de0 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 3 Oct 2022 13:52:09 -0700 Subject: [PATCH 4/6] Update Doc/reference/expressions.rst --- Doc/reference/expressions.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 0c1cb0c7b08329..27e6cf4fa6b99d 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1768,8 +1768,9 @@ Or, when processing a file stream in chunks: Assignment expressions must be surrounded by parentheses when used as sub-expressions in slicing, conditional, lambda, -keyword-argument, and comprehension-if expressions. They -can be used unparenthesized in all other places, including ``if`` and ``while`` statements. +keyword-argument, and comprehension-if expressions. +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. From 07b9fe5c290a08ad1c516f1850bf4d5a0a98d315 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 3 Oct 2022 13:53:45 -0700 Subject: [PATCH 5/6] Update Doc/reference/expressions.rst --- Doc/reference/expressions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 27e6cf4fa6b99d..beb60b8316f4fd 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1768,7 +1768,7 @@ Or, when processing a file stream in chunks: Assignment expressions must be surrounded by parentheses when used as sub-expressions in slicing, conditional, lambda, -keyword-argument, and comprehension-if expressions. +keyword-argument, and comprehension-if expressions. In all other places where they can be used, parentheses are not required, including in ``if`` and ``while`` statements. From a9d94bff2202e97c8f3b1b4bd3ac4c7d7e45e1ee Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 3 Oct 2022 15:56:40 -0700 Subject: [PATCH 6/6] Update Doc/reference/expressions.rst --- Doc/reference/expressions.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index beb60b8316f4fd..a661e03b173498 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1768,7 +1768,8 @@ Or, when processing a file stream in chunks: Assignment expressions must be surrounded by parentheses when used as sub-expressions in slicing, conditional, lambda, -keyword-argument, and comprehension-if expressions. +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. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy