pyflakes: False positive: unused import for quoted generic parameters and TypeVar bounds

Similar to #447, it seems that quoted types are not handled when passed as a generic parameter to a base class:

from typing import TYPE_CHECKING, Generic, TypeVar

if TYPE_CHECKING:
    # imagine this being some module that has circular imports
    from threading import Thread  # <--- pyflakes: 'threading.Thread' imported but unused

T = TypeVar("T")

class Base(Generic[T]):
    pass

class Derived(Base["Thread"]):
    pass

Perhaps worth a different issue, but the same thing occurs when using a bound for TypeVar:

from typing import TYPE_CHECKING, Generic, TypeVar

if TYPE_CHECKING:
    # imagine this being some module that has circular imports
    from threading import Thread  # <--- pyflakes: 'threading.Thread' imported but unused

T = TypeVar("T", bound="Thread")

class Base(Generic[T]):
    pass

Version information:

$ pyflakes --version
2.2.0 Python 3.6.8 on Linux

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

user generics can’t really be supported without solving some sort of halting problem – currently only types from the typing module are supported. could you please open a separate issue for the TypeVar(... bound=) bit?