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
- :label: Make registry/plugin definitions generics These help in returning the appropriate plugin class for further usage. Note that the string version of type annotations is required to resolve circ... — committed to open-formulieren/open-forms by sergei-maertens a year ago
- :label: Make registry/plugin definitions generics These help in returning the appropriate plugin class for further usage. Note that the string version of type annotations is required to resolve circ... — committed to open-formulieren/open-forms by sergei-maertens a year ago
- :label: Make registry/plugin definitions generics These help in returning the appropriate plugin class for further usage. Note that the string version of type annotations is required to resolve circ... — committed to open-formulieren/open-forms by sergei-maertens a year ago
user generics can’t really be supported without solving some sort of halting problem – currently only types from the
typingmodule are supported. could you please open a separate issue for theTypeVar(... bound=)bit?