Skip to content

Commit

Permalink
Relax type import detection for names that do not come from the ``typ…
Browse files Browse the repository at this point in the history
…ing`` module

Close #3191
  • Loading branch information
PCManticore committed Nov 13, 2019
1 parent c51afc0 commit 7946f13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -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?
===========================
Expand Down
6 changes: 1 addition & 5 deletions pylint/checkers/variables.py
Expand Up @@ -1671,17 +1671,13 @@ def _has_homonym_in_upper_function_scope(self, node, index):

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)
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/u/unused_typing_imports.py
Expand Up @@ -7,6 +7,7 @@

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

0 comments on commit 7946f13

Please sign in to comment.