Skip to content

Commit

Permalink
Raise A002 for lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
cielavenir committed Mar 18, 2024
1 parent e98d973 commit cb97ac8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flake8_builtins.py
Expand Up @@ -58,7 +58,7 @@ def run(self):
for child in ast.iter_child_nodes(statement):
child.__flake8_builtins_parent = statement

function_nodes = [ast.FunctionDef]
function_nodes = [ast.FunctionDef, ast.Lambda]
if getattr(ast, 'AsyncFunctionDef', None):
function_nodes.append(ast.AsyncFunctionDef)
function_nodes = tuple(function_nodes)
Expand Down Expand Up @@ -136,7 +136,7 @@ def check_assignment(self, statement):
stack.extend(list(item.value.elts))

def check_function_definition(self, statement):
if statement.name in self.names:
if not isinstance(statement, ast.Lambda) and statement.name in self.names:
msg = self.assign_msg
if type(statement.__flake8_builtins_parent) is ast.ClassDef:
msg = self.class_attribute_msg
Expand Down
5 changes: 5 additions & 0 deletions run_tests.py
Expand Up @@ -140,6 +140,11 @@ def bla(list):
check_code(source, 'A002')


def test_lambda_argument_message():
source = 'takefirst = lambda list: list[0]'
check_code(source, 'A002')


def test_keyword_argument_message():
source = """
def bla(dict=3):
Expand Down

0 comments on commit cb97ac8

Please sign in to comment.