A Flake8 plugin that identifies which Python imports should be moved into or out of type-checking blocks to improve performance and prevent circular imports.
flake8-type-checking is a Flake8 plugin that helps Python developers manage imports used exclusively for type hinting. It identifies which imports can be moved into `typing.TYPE_CHECKING` blocks to reduce runtime overhead and prevent import circularity issues. The plugin provides actionable error codes to refactor code for better performance and maintainability.
Python developers using type hints who want to optimize import performance, avoid circular imports, and maintain clean codebases, especially those working with large libraries or frameworks like FastAPI, Pydantic, or SQLAlchemy.
Developers choose this plugin because it automates the tedious process of managing type-checking imports, reduces runtime memory usage, and integrates seamlessly with popular Python frameworks to prevent false positives, ensuring reliable and efficient linting.
Flake8 plugin for managing type-checking imports & forward references.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Scans code to identify imports used only for type hints, providing specific error codes like TC001-TC003 for actionable refactoring, as shown in the pandas example.
Includes dedicated settings for Pydantic, FastAPI, SQLAlchemy, and others to minimize false positives, ensuring accurate linting in complex projects without manual overrides.
Helps refactor code to break import cycles by guarding type-only imports, demonstrated in the detailed circularity example with models A and B.
Eliminates runtime cost of heavy imports like pandas by moving them into TYPE_CHECKING blocks, directly reducing startup time and memory usage.
Requires managing multiple settings in flake8 config, such as enabling framework support and choosing between TC100/TC200 error ranges, which can be overwhelming for teams.
For FastAPI dependency support, it disables linting for all function annotations to prevent false positives, sacrificing precision for safety as admitted in the README.
Only works with Flake8, so projects using alternative linters like ruff cannot benefit without switching or integrating Flake8 into their workflow.