@@ -15,6 +15,7 @@ class BuiltinsChecker:
15
15
class_attribute_msg = 'A003 class attribute "{0}" is shadowing a Python builtin'
16
16
import_msg = 'A004 import statement "{0}" is shadowing a Python builtin'
17
17
module_name_msg = 'A005 the module is shadowing a Python builtin module "{0}"'
18
+ lambda_argument_msg = 'A006 lambda argument "{0}" is shadowing a Python builtin'
18
19
19
20
names = []
20
21
ignore_list = {
@@ -113,6 +114,9 @@ def run(self):
113
114
elif isinstance (statement , function_nodes ):
114
115
value = self .check_function_definition (statement )
115
116
117
+ elif isinstance (statement , ast .Lambda ):
118
+ value = self .check_lambda_definition (statement )
119
+
116
120
elif isinstance (statement , for_nodes ):
117
121
value = self .check_for_loop (statement )
118
122
@@ -181,6 +185,20 @@ def check_function_definition(self, statement):
181
185
variable = arg .arg ,
182
186
)
183
187
188
+ def check_lambda_definition (self , statement ):
189
+ all_arguments = []
190
+ all_arguments .extend (statement .args .args )
191
+ all_arguments .extend (getattr (statement .args , 'kwonlyargs' , []))
192
+ all_arguments .extend (getattr (statement .args , 'posonlyargs' , []))
193
+
194
+ for arg in all_arguments :
195
+ if isinstance (arg , ast .arg ) and arg .arg in self .names :
196
+ yield self .error (
197
+ arg ,
198
+ message = self .lambda_argument_msg ,
199
+ variable = arg .arg ,
200
+ )
201
+
184
202
def check_for_loop (self , statement ):
185
203
stack = [statement .target ]
186
204
while stack :
0 commit comments