Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,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.
Expand Down Expand Up @@ -1707,7 +1707,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.
Expand All @@ -1733,7 +1732,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
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========
Expand Down
Original file line number Diff line number Diff line change
@@ -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.