Skip to content

Commit

Permalink
Fix B008 edge case with lambda functions (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpy-git committed Mar 25, 2022
1 parent c255c1b commit 40a9381
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bugbear.py
Expand Up @@ -791,6 +791,11 @@ def visit_Call(self, node):
# Check for nested functions.
self.generic_visit(node)

def visit_Lambda(self, node):
# Don't recurse into lambda expressions
# as they are evaluated at call time.
pass

def visit(self, node):
"""Like super-visit but supports iteration over lists."""
self.arg_depth += 1
Expand Down
5 changes: 5 additions & 0 deletions tests/b006_b008.py
Expand Up @@ -180,3 +180,8 @@ def no_nested_b006(a=map(lambda s: s.upper(), ["a", "b", "c"])):
# B008-ception.
def nested_b008(a=random.randint(0, dt.datetime.now().year)):
pass


# Ignore lambda contents since they are evaluated at call time.
def foo(f=lambda x: print(x)):
f(1)
1 change: 0 additions & 1 deletion tests/test_bugbear.py
Expand Up @@ -124,7 +124,6 @@ def test_b006_b008(self):
B008(170, 20),
B008(170, 30),
B008(176, 21),
B008(176, 35),
B008(181, 18),
B008(181, 36),
),
Expand Down

0 comments on commit 40a9381

Please sign in to comment.