Skip to content

Commit 93cf3b2

Browse files
Jesus Zapatamoylop260
authored andcommitted
[FIX] attribute-string-redundant: Add "isinstance" validation for nodes
Fix #109
1 parent 4fa6c37 commit 93cf3b2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pylint_odoo/checkers/no_modules.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,15 @@ def visit_call(self, node):
378378
if node.as_string().lower().startswith('fields.'):
379379
args = misc.join_node_args_kwargs(node)
380380
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('_', ' '))
381387
for argument in args:
382388
argument_aux = argument
383389
# Check this 'name = fields.Char("name")'
384-
field_name = (argument.parent.parent.targets[0].name
385-
.replace('_', ' '))
386390
if (isinstance(argument, astroid.Const) and
387391
(index ==
388392
FIELDS_METHOD.get(argument.parent.func.attrname, 0)) and
@@ -402,7 +406,8 @@ def visit_call(self, node):
402406
# Check if the param string is equal to the name
403407
# of variable
404408
elif argument.arg == 'string' and \
405-
(argument.value.value in
409+
(isinstance(argument_aux, astroid.Const) and
410+
argument_aux.value in
406411
[field_name.capitalize(), field_name.title()]):
407412
self.add_message(
408413
'attribute-string-redundant', node=node)

0 commit comments

Comments
 (0)