mirror of
https://github.com/davidhalter/parso.git
synced 2026-02-20 16:48:54 +08:00
Fix the lambda issues.
This commit is contained in:
@@ -47,7 +47,10 @@ class PEP8Normalizer(Normalizer):
|
|||||||
for name in names[:1]:
|
for name in names[:1]:
|
||||||
self.add_issue(401, 'Multiple imports on one line', name)
|
self.add_issue(401, 'Multiple imports on one line', name)
|
||||||
elif typ == 'lambdef':
|
elif typ == 'lambdef':
|
||||||
if node.parent.type == 'expr_stmt':
|
expr_stmt = node.parent
|
||||||
|
# Check if it's simply defining a single name, not something like
|
||||||
|
# foo.bar or x[1], where using a lambda could make more sense.
|
||||||
|
if expr_stmt.type == 'expr_stmt' and any(n.type == 'name' for n in expr_stmt.children[:-2:2]):
|
||||||
self.add_issue(731, 'Do not assign a lambda expression, use a def', node)
|
self.add_issue(731, 'Do not assign a lambda expression, use a def', node)
|
||||||
elif typ == 'try_stmt':
|
elif typ == 'try_stmt':
|
||||||
for child in node.children:
|
for child in node.children:
|
||||||
|
|||||||
16
test/normalizer_issue_files/E73.py
Normal file
16
test/normalizer_issue_files/E73.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#: E731:4
|
||||||
|
f = lambda x: 2 * x
|
||||||
|
while False:
|
||||||
|
#: E731:6
|
||||||
|
foo = lambda y, z: 2 * x
|
||||||
|
# Okay
|
||||||
|
f = object()
|
||||||
|
f.method = lambda: 'Method'
|
||||||
|
|
||||||
|
f = {}
|
||||||
|
f['a'] = lambda x: x ** 2
|
||||||
|
|
||||||
|
f = []
|
||||||
|
f.append(lambda x: x ** 2)
|
||||||
|
|
||||||
|
lambda: 'no-op'
|
||||||
Reference in New Issue
Block a user