diff options
| author | Michal Nowikowski <godfryd@gmail.com> | 2014-08-04 06:41:14 +0200 |
|---|---|---|
| committer | Michal Nowikowski <godfryd@gmail.com> | 2014-08-04 06:41:14 +0200 |
| commit | 5ad40ab704e2f2351374b4a8ab8aa0bbd494eecb (patch) | |
| tree | 4a6023ae110b72f3eeab684dc8037c87c5c42127 /checkers/variables.py | |
| parent | 098c289fc12910ccfecef8015934caee14fb1774 (diff) | |
| download | pylint-git-5ad40ab704e2f2351374b4a8ab8aa0bbd494eecb.tar.gz | |
Review fixes.
--HG--
branch : fix-293
Diffstat (limited to 'checkers/variables.py')
| -rw-r--r-- | checkers/variables.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index 68dd0d50b..b2f27dee3 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -320,20 +320,26 @@ builtins. Remember that you should avoid to define new builtins when possible.' for stmt in stmts): continue for stmt in stmts: + if not isinstance(stmt, astroid.Import) and not isinstance(stmt, astroid.From): + continue + + imported_name = stmt.names[0][0] # this is: 'import imported_name' or 'from something import imported_name' + as_name = stmt.names[0][1] # this is: 'import imported_name as as_name' + if isinstance(stmt, astroid.Import): - if stmt.names[0][1] is None: - msg = "import %s" % stmt.names[0][0] + if as_name is None: + msg = "import %s" % imported_name else: - msg = "%s imported as %s" % (stmt.names[0][0], stmt.names[0][1]) + msg = "%s imported as %s" % (imported_name, as_name) self.add_message('unused-import', args=msg, node=stmt) elif isinstance(stmt, astroid.From) and stmt.modname != '__future__': - if stmt.names[0][0] == '*': + if imported_name == '*': self.add_message('unused-wildcard-import', args=name, node=stmt) else: - if stmt.names[0][1] is None: - msg = "%s imported from %s" % (stmt.names[0][0], stmt.modname) + if as_name is None: + msg = "%s imported from %s" % (imported_name, stmt.modname) else: - msg = "%s imported from %s as %s" % (stmt.names[0][0], stmt.modname, stmt.names[0][1]) + msg = "%s imported from %s as %s" % (imported_name, stmt.modname, as_name) self.add_message('unused-import', args=msg, node=stmt) del self._to_consume |
