summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-11-13 08:34:04 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2019-11-13 08:34:04 +0100
commit7946f13c27a422d8c55c553c670d4062b47f7bc0 (patch)
treeb211a15da1ee229d418f81b7626364368fb585e8
parentc51afc0fa6f757587701e251f07e96cc9c6b70d8 (diff)
downloadpylint-git-7946f13c27a422d8c55c553c670d4062b47f7bc0.tar.gz
Relax type import detection for names that do not come from the ``typing`` module
Close #3191
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/variables.py6
-rw-r--r--tests/functional/u/unused_typing_imports.py6
3 files changed, 11 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 1fb8da261..e75082636 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,10 @@ Release date: TBA
Close #3112
+* Relax type import detection for names that do not come from the ``typing`` module
+
+ Close #3191
+
What's New in Pylint 2.4.3?
===========================
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index c278bb859..e13f9b51c 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -1671,17 +1671,13 @@ class VariablesChecker(BaseChecker):
def _store_type_annotation_node(self, type_annotation):
"""Given a type annotation, store all the name nodes it refers to"""
- if (
- isinstance(type_annotation, astroid.Name)
- and type_annotation.name in TYPING_NAMES
- ):
+ if isinstance(type_annotation, astroid.Name):
self._type_annotation_names.append(type_annotation.name)
return
if not isinstance(type_annotation, astroid.Subscript):
return
- # Check if it is namespaced by typing or not.
if (
isinstance(type_annotation.value, astroid.Attribute)
and isinstance(type_annotation.value.expr, astroid.Name)
diff --git a/tests/functional/u/unused_typing_imports.py b/tests/functional/u/unused_typing_imports.py
index 4c122a622..c0a2f4986 100644
--- a/tests/functional/u/unused_typing_imports.py
+++ b/tests/functional/u/unused_typing_imports.py
@@ -7,6 +7,7 @@ which means we were never processing them.
import re
import typing
+from collections import defaultdict
from datetime import datetime
from typing import (
Any,
@@ -70,3 +71,8 @@ def magic(alpha, beta, gamma):
# type: (str, Optional[str], Optional[datetime]) -> Any
"""going strong"""
return alpha, beta, gamma
+
+
+def unused_assignment_import():
+ foo_or_bar = defaultdict(int) # type: defaultdict
+ return foo_or_bar