From 5ad40ab704e2f2351374b4a8ab8aa0bbd494eecb Mon Sep 17 00:00:00 2001 From: Michal Nowikowski Date: Mon, 4 Aug 2014 06:41:14 +0200 Subject: Review fixes. --HG-- branch : fix-293 --- checkers/variables.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'checkers/variables.py') 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 -- cgit v1.2.1