[Python-checkins] bpo-43755: Update docs to reflect that lambda is not allowed in `comp_if` since 3.9 (GH-25231) (GH-25233)
pablogsal
webhook-mailer at python.org
Wed Apr 7 14:18:04 EDT 2021
https://github.com/python/cpython/commit/f91fc7a679e076cb9a703f6db4d95b63935562e3
commit: f91fc7a679e076cb9a703f6db4d95b63935562e3
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-04-07T19:17:56+01:00
summary:
bpo-43755: Update docs to reflect that lambda is not allowed in `comp_if` since 3.9 (GH-25231) (GH-25233)
files:
A Misc/NEWS.d/next/Documentation/2021-04-06-14-55-45.bpo-43755.1m0fGq.rst
M Doc/reference/expressions.rst
M Doc/whatsnew/3.9.rst
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index 9b1a395b724d9..e7b1d3838be35 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -183,7 +183,7 @@ Common syntax elements for comprehensions are:
comprehension: `assignment_expression` `comp_for`
comp_for: ["async"] "for" `target_list` "in" `or_test` [`comp_iter`]
comp_iter: `comp_for` | `comp_if`
- comp_if: "if" `expression_nocond` [`comp_iter`]
+ comp_if: "if" `or_test` [`comp_iter`]
The comprehension consists of a single expression followed by at least one
:keyword:`!for` clause and zero or more :keyword:`!for` or :keyword:`!if` clauses.
@@ -1695,7 +1695,6 @@ Conditional expressions
.. productionlist:: python-grammar
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
expression: `conditional_expression` | `lambda_expr`
- expression_nocond: `or_test` | `lambda_expr_nocond`
Conditional expressions (sometimes called a "ternary operator") have the lowest
priority of all Python operations.
@@ -1721,7 +1720,6 @@ Lambdas
.. productionlist:: python-grammar
lambda_expr: "lambda" [`parameter_list`] ":" `expression`
- lambda_expr_nocond: "lambda" [`parameter_list`] ":" `expression_nocond`
Lambda expressions (sometimes called lambda forms) are used to create anonymous
functions. The expression ``lambda parameters: expression`` yields a function
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 4cb49406d6b77..d5eaccacde67a 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -267,6 +267,10 @@ Other Language Changes
:func:`~operator.countOf` of the :mod:`operator` module.
(Contributed by Serhiy Storchaka in :issue:`40824`.)
+* Unparenthesized lambda expressions can no longer be the expression part in an
+ ``if`` clause in comprehensions and generator expressions. See :issue:`41848`
+ and :issue:`43755` for details.
+
New Modules
===========
diff --git a/Misc/NEWS.d/next/Documentation/2021-04-06-14-55-45.bpo-43755.1m0fGq.rst b/Misc/NEWS.d/next/Documentation/2021-04-06-14-55-45.bpo-43755.1m0fGq.rst
new file mode 100644
index 0000000000000..53cba0b47d6d3
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2021-04-06-14-55-45.bpo-43755.1m0fGq.rst
@@ -0,0 +1,3 @@
+Update documentation to reflect that unparenthesized lambda expressions can
+no longer be the expression part in an ``if`` clause in comprehensions and
+generator expressions since Python 3.9.
More information about the Python-checkins
mailing list