Skip to content

Commit f91fc7a

Browse files
bpo-43755: Update docs to reflect that lambda is not allowed in comp_if since 3.9 (GH-25231) (GH-25233)
1 parent 34f9300 commit f91fc7a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Doc/reference/expressions.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Common syntax elements for comprehensions are:
183183
comprehension: `assignment_expression` `comp_for`
184184
comp_for: ["async"] "for" `target_list` "in" `or_test` [`comp_iter`]
185185
comp_iter: `comp_for` | `comp_if`
186-
comp_if: "if" `expression_nocond` [`comp_iter`]
186+
comp_if: "if" `or_test` [`comp_iter`]
187187

188188
The comprehension consists of a single expression followed by at least one
189189
:keyword:`!for` clause and zero or more :keyword:`!for` or :keyword:`!if` clauses.
@@ -1695,7 +1695,6 @@ Conditional expressions
16951695
.. productionlist:: python-grammar
16961696
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
16971697
expression: `conditional_expression` | `lambda_expr`
1698-
expression_nocond: `or_test` | `lambda_expr_nocond`
16991698

17001699
Conditional expressions (sometimes called a "ternary operator") have the lowest
17011700
priority of all Python operations.
@@ -1721,7 +1720,6 @@ Lambdas
17211720

17221721
.. productionlist:: python-grammar
17231722
lambda_expr: "lambda" [`parameter_list`] ":" `expression`
1724-
lambda_expr_nocond: "lambda" [`parameter_list`] ":" `expression_nocond`
17251723

17261724
Lambda expressions (sometimes called lambda forms) are used to create anonymous
17271725
functions. The expression ``lambda parameters: expression`` yields a function

Doc/whatsnew/3.9.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ Other Language Changes
267267
:func:`~operator.countOf` of the :mod:`operator` module.
268268
(Contributed by Serhiy Storchaka in :issue:`40824`.)
269269

270+
* Unparenthesized lambda expressions can no longer be the expression part in an
271+
``if`` clause in comprehensions and generator expressions. See :issue:`41848`
272+
and :issue:`43755` for details.
273+
270274

271275
New Modules
272276
===========
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Update documentation to reflect that unparenthesized lambda expressions can
2+
no longer be the expression part in an ``if`` clause in comprehensions and
3+
generator expressions since Python 3.9.

0 commit comments

Comments
 (0)