flake8-import-type is a Flake8 plugin that encourages importing modules
instead of importing the types and functions used from them. Module-qualified
names make the origin of a symbol visible at its use site and reduce ambiguity
when several modules expose similarly named objects.
Install the plugin into the same environment as Flake8:
python -m pip install flake8 flake8-import-typeThe plugin is enabled automatically. If your Flake8 configuration uses
select, include IMT or IMT001:
flake8 --select IMT path/to/codeThis code reports IMT001 at the imported name:
from pathlib import Path
path = Path("file.txt")example.py:1:21: IMT001 Importing type/function `Path` from module `pathlib`.
Import and qualify the module instead:
import pathlib
path = pathlib.Path("file.txt")The plugin reports a from ... import ... binding when it is subsequently
used as:
- a direct callable, including a decorator;
- a type in an annotation or explicit string annotation;
- a class base, including a subscripted base;
- a metaclass;
- the value of a Python 3.12
typealias.
Each imported binding produces at most one diagnostic. Aliases are shown by their local name:
from pathlib import Path as FilePath
path = FilePath("file.txt") # IMT001 is reported at `FilePath` in the importImports from the following modules are exempt:
__future__collections.abcsix.movestypingtyping_extensions
Suppress an intentional direct import with a normal Flake8 suppression:
from package import Factory # noqa: IMT001
Factory()flake8-import-type supports Python 3.9 through 3.14 and Flake8 7.0 or newer.
The check is syntactic and processes bindings in source order. It does not
perform control-flow or runtime type inference, so it cannot determine whether
a conditional import executes or whether an imported object is actually a
class or function. Legacy # type: comments are not checked because the AST
provided by Flake8 does not retain them.
The project uses uv:
uv sync --dev
uv run pytest
uv run ruff check .
uv build
uv run twine check dist/*CI runs the tests on every supported Python version, verifies the minimum Flake8 version, and validates the distributions.
- Update the version in
pyproject.tomland merge the change. - Publish a GitHub Release whose tag is exactly
v<version>, such asv0.1.0. - Approve the protected
pypienvironment deployment.
The release workflow checks the tag, builds and validates the distributions, and publishes them through PyPI Trusted Publishing. No PyPI API token is stored in GitHub.
This project is distributed under the MIT License.