skillfed

flake8-type-checking

A flake8 plugin for managing type-checking imports & forward references

flake8-type-checking v3.2.0 109.1K downloads/30d#12,529 on PyPI128
Permissive license BSD-3-Clause Active released

What it is and what it does

This flake8 plugin analyzes your code to detect imports used only for type hints and suggests moving them into TYPE_CHECKING blocks. By guarding type-only imports behind TYPE_CHECKING, you eliminate their runtime overhead (important for large libraries like pandas), reduce circular import issues, and organize imports more cleanly. The plugin works by classifying imports as application, third-party, or built-in, then checking whether they're actually used at runtime or only in annotations.

It offers two strategies for handling forward references: TC100-range codes use postponed evaluation (from __future__ import annotations), while TC200-range codes use string literals. You configure which strategy suits your codebase and Python version target. The plugin includes special handling for frameworks like Pydantic and FastAPI, where class annotations are evaluated at runtime, and can be tuned with strict mode, exemptions, and custom typing module paths.

Use it for:

  • Reduce import overhead in libraries that use heavy dependencies only for type hints (e.g., pandas, numpy).
  • Eliminate circular import errors by moving type-only imports into TYPE_CHECKING blocks.
  • Enforce consistent forward-reference style across a codebase (either future annotations or string literals).
  • Validate that Pydantic or FastAPI models don't incorrectly guard runtime-needed imports.
  • Organize and lint type-checking imports as part of your standard flake8 checks.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A flake8 plugin that identifies which imports should be moved into or out of TYPE_CHECKING blocks to reduce runtime overhead, circular dependencies, and improve code organization.

Yes. This is a focused, low-friction plugin that solves a real problem—unnecessary runtime import overhead and circular dependencies—with active maintenance, no security issues, and permissive licensing. Install it if you want automated guidance on moving type-only imports into TYPE_CHECKING blocks.

Install

flake8-type-checking on PyPI

pip

pip install flake8-type-checking

uv

uv add flake8-type-checking

poetry

poetry add flake8-type-checking

Installing flake8-type-checking

Before you install

Low friction install with just two runtime dependencies (flake8 and classify-imports). The package is actively maintained with a recent release and supports current Python versions (3.10–3.14).

License in practice

BSD-3-Clause is a permissive license with no restrictions on use, modification, or distribution in proprietary or open-source projects.

Quickstart

pip install flake8-type-checking

# Add to .flake8 config:
# [flake8]
# extend-select = TC, TC2

# Then run flake8 as usual; the plugin will flag imports to move

Requires flake8 to be installed and Python 3.10 or later.

Verify before relying

  • Whether the plugin's inference works correctly with all pydantic, fastapi, cattrs, and injector patterns in real codebases.
  • Performance impact when running on large projects with many type-checking blocks.

Package facts

License BSD-3-Clause (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 2 — classify-imports, flake8
Maintenance actively maintained — 177 days since the last release
Last repo commit
First released
Downloads 109,061/month — #12,529 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: flake8_type_checking-3.2.0-py3-none-any.whl

Keywords: flake8, plugin, linting, type hint, typing, imports

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Quality AssuranceTyping :: Typed

Tags

flake8 type checking importsmove imports type checking blockreduce import overhead pythoncircular dependency importstype hint import lintingforward reference managementruntime import optimization
flake8-plugintype-checkingimport-optimization

More Quality Assurance packages