A Flake8 plugin that identifies which Python imports should be moved into or out of typing.TYPE_CHECKING blocks to optimize runtime 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 should be moved into `typing.TYPE_CHECKING` blocks to avoid runtime evaluation, reducing import overhead and preventing circular dependencies. The plugin also guides users on handling forward references through string literals or postponed annotations.
Python developers who use type hints extensively and want to optimize their code's runtime performance and maintainability, particularly those working with large codebases or heavy libraries like pandas.
It automates the tedious process of manually managing type-checking imports, reduces the risk of import cycles, and eliminates unnecessary runtime imports, leading to cleaner and faster Python code.
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.
Identifies imports used solely for type hints and suggests moving them to TYPE_CHECKING blocks, reducing runtime overhead as demonstrated with pandas examples.
Includes configurable options for Pydantic, FastAPI, SQLAlchemy, and others to prevent false positives in common scenarios, ensuring accurate linting.
Helps eliminate import cycles by guarding type-only imports, improving code maintainability in large projects, as outlined in the rationale.
Provides specific error codes for different import types and forward reference strategies, making it easy to understand and fix issues.
Requires managing multiple boolean and list settings for framework support, which can be intricate and error-prone, especially for teams new to the plugin.
Forces a choice between string literals (TC2) or future imports (TC1) for forward references, which may not align with all coding styles or cause confusion during adoption.
For FastAPI, enabling dependency support stops linting all function annotations entirely, a trade-off that might hide legitimate issues beyond dependencies.