diff options
author | cpopa <devnull@localhost> | 2014-05-02 09:36:01 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-05-02 09:36:01 +0300 |
commit | f44c9a1cdcf3c9983a712672e0342cb8dd489f7a (patch) | |
tree | ac7770480e895cded01ad9cda5a4a8c427143eb4 /checkers/variables.py | |
parent | 6d031115a314d9f8cf663b6021adde79ede8a2f5 (diff) | |
download | pylint-f44c9a1cdcf3c9983a712672e0342cb8dd489f7a.tar.gz |
Fix unused-import false positive with Python 3 metaclasses. Closes issue #143.
Diffstat (limited to 'checkers/variables.py')
-rw-r--r-- | checkers/variables.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index a6123de..dc8d111 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -716,6 +716,22 @@ class VariablesChecker3k(VariablesChecker): # do not check for not used locals here self._to_consume.pop() + def leave_module(self, node): + """ Update consumption analysis variable + for metaclasses. + """ + for klass in node.nodes_of_class(astroid.Class): + if klass._metaclass: + metaclass = klass.metaclass() + module_locals = self._to_consume[0][0] + + if isinstance(klass._metaclass, astroid.Name): + module_locals.pop(klass._metaclass.name, None) + if metaclass: + # if it uses a `metaclass=module.Class` + module_locals.pop(metaclass.root().name, None) + super(VariablesChecker3k, self).leave_module(node) + if sys.version_info >= (3, 0): VariablesChecker = VariablesChecker3k |