Derived from the flake8-type-checking linter.
Autofix is sometimes available.
What it does#
Checks for standard library imports that are only used for type annotations, but aren't defined in a type-checking block.
Why is this bad?#
Unused imports add a performance overhead at runtime, and risk creating
import cycles. If an import is only used in typing-only contexts, it can
instead be imported conditionally under an
if TYPE_CHECKING: block to
minimize runtime overhead.
If a class requires that type annotations be available at runtime (as is
the case for Pydantic, SQLAlchemy, and other libraries), consider using
flake8-type-checking.runtime-evaluated-decorators settings to mark them