PEP 572: Add bullet point for lambda (#729)

Closes #728
This commit is contained in:
Chris Angelico 2018-07-11 09:38:31 +10:00 committed by Guido van Rossum
parent 00c19f4a82
commit f906b988b2
1 changed files with 14 additions and 0 deletions

View File

@ -201,6 +201,20 @@ in order to avoid ambiguities or user confusion:
ungrouped assortment of symbols and operators composed of ``:`` and
``=`` is hard to read correctly.
- Unparenthesized assignment expressions are prohibited in lambda functions.
Example::
(lambda: x := 1) # INVALID
lambda: (x := 1) # Valid, but unlikely to be useful
(x := lambda: 1) # Valid
lambda line: (m := re.match(pattern, line)) and m.group(1) # Valid
This allows ``lambda`` to always bind less tightly than ``:=``; having a
name binding at the top level inside a lambda function is unlikely to be of
value, as there is no way to make use of it. In cases where the name will be
used more than once, the expression is likely to need parenthesizing anyway,
so this prohibition will rarely affect code.
Scope of the target
-------------------