summaryrefslogtreecommitdiff
path: root/pylint/checkers/variables.py
diff options
context:
space:
mode:
authorRadu Ciorba <radu@devrandom.ro>2015-03-30 01:40:02 +0300
committerRadu Ciorba <radu@devrandom.ro>2015-03-30 01:40:02 +0300
commit04b087b0ff20b1113943ef14814fbca06ae5b1ad (patch)
tree31862bb4c68388f7ed2d15ba59bfc42a6d625a5c /pylint/checkers/variables.py
parent06738a9cae6e6b8e2fe39c485e1a411b63c0c910 (diff)
downloadpylint-04b087b0ff20b1113943ef14814fbca06ae5b1ad.tar.gz
fix unused-import false positive when the import is used in a class assignment
don't consume from current scope if it's defined in the same statement
Diffstat (limited to 'pylint/checkers/variables.py')
-rw-r--r--pylint/checkers/variables.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index d626013..9cc747d 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -329,7 +329,7 @@ builtins. Remember that you should avoid to define new builtins when possible.'
)
def __init__(self, linter=None):
BaseChecker.__init__(self, linter)
- self._to_consume = None
+ self._to_consume = None # list of tuples: (to_consume:dict, consumed:dict, scope_type:str)
self._checking_mod_attr = None
def visit_module(self, node):
@@ -790,10 +790,16 @@ builtins. Remember that you should avoid to define new builtins when possible.'
self._loopvar_name(node, name)
break
# mark the name as consumed if it's defined in this scope
- # (i.e. no KeyError is raised by "to_consume[name]")
- try:
- consumed[name] = to_consume[name]
- except KeyError:
+ found_node = to_consume.get(name)
+ if (found_node
+ and isinstance(node.parent, astroid.Assign)
+ and node.parent == found_node[0].parent):
+ lhs = found_node[0].parent.targets[0]
+ if lhs.name == name: # this name is being in this very statement
+ found_node = None
+ if found_node:
+ consumed[name] = found_node
+ else:
continue
# checks for use before assignment
defnode = assign_parent(to_consume[name][0])