diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2019-11-08 17:04:12 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-11-08 17:06:17 +0100 |
commit | 2ac25f63bc9e34cefd18c55751a36e30c16d7d14 (patch) | |
tree | 17640242da68d37ba75f3ee1a9bef7b49fc3e4bc | |
parent | 7807af3a9d956f885e1ab94e01c915ca7db3b03f (diff) | |
download | pylint-git-2ac25f63bc9e34cefd18c55751a36e30c16d7d14.tar.gz |
Exempt all the names found in type annotations from ``unused-import``
The previous code was assuming that only ``typing`` names need to be
exempted, but we need to do that for the rest of the type comment
names as well.
Close #3112
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | pylint/checkers/variables.py | 1 | ||||
-rw-r--r-- | tests/functional/u/unused_typing_imports.py | 7 |
3 files changed, 20 insertions, 1 deletions
@@ -2,6 +2,19 @@ Pylint's ChangeLog ------------------ +What's New in Pylint 2.4.4? +=========================== +Release date: TBA + +* Exempt all the names found in type annotations from ``unused-import`` + + The previous code was assuming that only ``typing`` names need to be + exempted, but we need to do that for the rest of the type comment + names as well. + + Close #3112 + + What's New in Pylint 2.4.3? =========================== diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index bc53fb9f5..c278bb859 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1693,7 +1693,6 @@ class VariablesChecker(BaseChecker): self._type_annotation_names.extend( annotation.name for annotation in type_annotation.nodes_of_class(astroid.Name) - if annotation.name in TYPING_NAMES ) def _store_type_annotation_names(self, node): diff --git a/tests/functional/u/unused_typing_imports.py b/tests/functional/u/unused_typing_imports.py index add2316ce..4c122a622 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 datetime import datetime from typing import ( Any, Callable, @@ -63,3 +64,9 @@ def function(arg1, # type: Iterable # type: (...) -> Sequence """docstring""" print(arg1, arg2) + + +def magic(alpha, beta, gamma): + # type: (str, Optional[str], Optional[datetime]) -> Any + """going strong""" + return alpha, beta, gamma |