From 93cf3b2591557e5ebac648149e79a52fed24d81e Mon Sep 17 00:00:00 2001 From: Jesus Zapata Date: Mon, 30 Jan 2017 17:04:16 -0400 Subject: [PATCH] [FIX] attribute-string-redundant: Add "isinstance" validation for nodes Fix https://github.com/OCA/pylint-odoo/issues/109 --- pylint_odoo/checkers/no_modules.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pylint_odoo/checkers/no_modules.py b/pylint_odoo/checkers/no_modules.py index 692a3a81..16cc3931 100644 --- a/pylint_odoo/checkers/no_modules.py +++ b/pylint_odoo/checkers/no_modules.py @@ -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 @@ -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)