summaryrefslogtreecommitdiff
path: root/pylint/checkers/variables.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-05-23 08:53:09 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-05-23 08:54:25 +0200
commit3bfec9f63b53abd11131c164c4fa941ee1743286 (patch)
tree4c6b3135caf1c7b78fd21ec9d19fa67ea49b08eb /pylint/checkers/variables.py
parentb657df6644740e77fa167d4f95c76c4c007d2a49 (diff)
downloadpylint-git-3bfec9f63b53abd11131c164c4fa941ee1743286.tar.gz
``unused-import`` emitted for the right import names in function scopes.
Close #2928
Diffstat (limited to 'pylint/checkers/variables.py')
-rw-r--r--pylint/checkers/variables.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index c91880c24..921b8e749 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -841,7 +841,6 @@ class VariablesChecker(BaseChecker):
if not self._is_type_checking_import(stmt):
self.add_message("unused-import", args=msg, node=stmt)
elif isinstance(stmt, astroid.ImportFrom) and stmt.modname != FUTURE:
-
if SPECIAL_OBJ.search(imported_name):
# Filter special objects (__doc__, __all__) etc.,
# because they can be imported for exporting.
@@ -1034,10 +1033,18 @@ class VariablesChecker(BaseChecker):
if name in nonlocal_names:
return
+ qname = asname = None
if isinstance(stmt, (astroid.Import, astroid.ImportFrom)):
# Need the complete name, which we don't have in .locals.
- qname, asname = stmt.names[0]
- name = asname or qname
+ if len(stmt.names) > 1:
+ import_names = next(
+ (names for names in stmt.names if name in names), None
+ )
+ else:
+ import_names = stmt.names[0]
+ if import_names:
+ qname, asname = import_names
+ name = asname or qname
if _has_locals_call_after_node(stmt, node.scope()):
message_name = "possibly-unused-variable"