Skip to content

Commit

Permalink
[FIX] attribute-string-redundant: Add "isinstance" validation for nodes
Browse files Browse the repository at this point in the history
Fix #109
  • Loading branch information
Jesus Zapata authored and moylop260 committed Jan 30, 2017
1 parent 4fa6c37 commit 93cf3b2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pylint_odoo/checkers/no_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,15 @@ def visit_call(self, node):
if node.as_string().lower().startswith('fields.'):
args = misc.join_node_args_kwargs(node)
index = 0
field_name = ''
if (isinstance(node.parent, astroid.Assign) and
node.parent.targets and
isinstance(node.parent.targets[0], astroid.AssignName)):
field_name = (node.parent.targets[0].name
.replace('_', ' '))
for argument in args:
argument_aux = argument
# Check this 'name = fields.Char("name")'
field_name = (argument.parent.parent.targets[0].name
.replace('_', ' '))
if (isinstance(argument, astroid.Const) and
(index ==
FIELDS_METHOD.get(argument.parent.func.attrname, 0)) and
Expand All @@ -402,7 +406,8 @@ def visit_call(self, node):
# Check if the param string is equal to the name
# of variable
elif argument.arg == 'string' and \
(argument.value.value in
(isinstance(argument_aux, astroid.Const) and
argument_aux.value in
[field_name.capitalize(), field_name.title()]):
self.add_message(
'attribute-string-redundant', node=node)
Expand Down

0 comments on commit 93cf3b2

Please sign in to comment.