Skip to content

Commit cb97ac8

Browse files
committed
Raise A002 for lambda
1 parent e98d973 commit cb97ac8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

flake8_builtins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def run(self):
5858
for child in ast.iter_child_nodes(statement):
5959
child.__flake8_builtins_parent = statement
6060

61-
function_nodes = [ast.FunctionDef]
61+
function_nodes = [ast.FunctionDef, ast.Lambda]
6262
if getattr(ast, 'AsyncFunctionDef', None):
6363
function_nodes.append(ast.AsyncFunctionDef)
6464
function_nodes = tuple(function_nodes)
@@ -136,7 +136,7 @@ def check_assignment(self, statement):
136136
stack.extend(list(item.value.elts))
137137

138138
def check_function_definition(self, statement):
139-
if statement.name in self.names:
139+
if not isinstance(statement, ast.Lambda) and statement.name in self.names:
140140
msg = self.assign_msg
141141
if type(statement.__flake8_builtins_parent) is ast.ClassDef:
142142
msg = self.class_attribute_msg

run_tests.py

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def bla(list):
140140
check_code(source, 'A002')
141141

142142

143+
def test_lambda_argument_message():
144+
source = 'takefirst = lambda list: list[0]'
145+
check_code(source, 'A002')
146+
147+
143148
def test_keyword_argument_message():
144149
source = """
145150
def bla(dict=3):

0 commit comments

Comments
 (0)