File tree 1 file changed +14
-0
lines changed 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,20 @@ in order to avoid ambiguities or user confusion:
201
201
ungrouped assortment of symbols and operators composed of ``: `` and
202
202
``= `` is hard to read correctly.
203
203
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
+
204
218
Scope of the target
205
219
-------------------
206
220
You can’t perform that action at this time.
0 commit comments