parent
00c19f4a82
commit
f906b988b2
14
pep-0572.rst
14
pep-0572.rst
|
@ -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
|
||||
-------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue