Skip to content

Commit

Permalink
Exempt all the names found in type annotations from unused-import
Browse files Browse the repository at this point in the history
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
  • Loading branch information
PCManticore committed Nov 8, 2019
1 parent d00e191 commit 4e21e45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ChangeLog
Expand Up @@ -52,6 +52,19 @@ Release date: TBA
Closes #2956


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?
===========================

Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/variables.py
Expand Up @@ -1694,7 +1694,6 @@ def _store_type_annotation_node(self, type_annotation):
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):
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/u/unused_typing_imports.py
Expand Up @@ -7,6 +7,7 @@

import re
import typing
from datetime import datetime
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -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

0 comments on commit 4e21e45

Please sign in to comment.