File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -378,11 +378,15 @@ def visit_call(self, node):
378
378
if node .as_string ().lower ().startswith ('fields.' ):
379
379
args = misc .join_node_args_kwargs (node )
380
380
index = 0
381
+ field_name = ''
382
+ if (isinstance (node .parent , astroid .Assign ) and
383
+ node .parent .targets and
384
+ isinstance (node .parent .targets [0 ], astroid .AssignName )):
385
+ field_name = (node .parent .targets [0 ].name
386
+ .replace ('_' , ' ' ))
381
387
for argument in args :
382
388
argument_aux = argument
383
389
# Check this 'name = fields.Char("name")'
384
- field_name = (argument .parent .parent .targets [0 ].name
385
- .replace ('_' , ' ' ))
386
390
if (isinstance (argument , astroid .Const ) and
387
391
(index ==
388
392
FIELDS_METHOD .get (argument .parent .func .attrname , 0 )) and
@@ -402,7 +406,8 @@ def visit_call(self, node):
402
406
# Check if the param string is equal to the name
403
407
# of variable
404
408
elif argument .arg == 'string' and \
405
- (argument .value .value in
409
+ (isinstance (argument_aux , astroid .Const ) and
410
+ argument_aux .value in
406
411
[field_name .capitalize (), field_name .title ()]):
407
412
self .add_message (
408
413
'attribute-string-redundant' , node = node )
You can’t perform that action at this time.
0 commit comments