Skip to content

Commit f906b98

Browse files
Rosuavgvanrossum
authored andcommitted
PEP 572: Add bullet point for lambda (#729)
Closes #728
1 parent 00c19f4 commit f906b98

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pep-0572.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ in order to avoid ambiguities or user confusion:
201201
ungrouped assortment of symbols and operators composed of ``:`` and
202202
``=`` is hard to read correctly.
203203

204+
- Unparenthesized assignment expressions are prohibited in lambda functions.
205+
Example::
206+
207+
(lambda: x := 1) # INVALID
208+
lambda: (x := 1) # Valid, but unlikely to be useful
209+
(x := lambda: 1) # Valid
210+
lambda line: (m := re.match(pattern, line)) and m.group(1) # Valid
211+
212+
This allows ``lambda`` to always bind less tightly than ``:=``; having a
213+
name binding at the top level inside a lambda function is unlikely to be of
214+
value, as there is no way to make use of it. In cases where the name will be
215+
used more than once, the expression is likely to need parenthesizing anyway,
216+
so this prohibition will rarely affect code.
217+
204218
Scope of the target
205219
-------------------
206220

0 commit comments

Comments
 (0)