Skip to main content

flake8-import-type

CI

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.

Installation

Install the plugin into the same environment as Flake8:

python -m pip install flake8 flake8-import-type

The plugin is enabled automatically. If your Flake8 configuration uses select, include IMT or IMT001:

flake8 --select IMT path/to/code

Rule

IMT001: directly imported type or function

This 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 type alias.

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 import

Imports from the following modules are exempt:

  • __future__
  • collections.abc
  • six.moves
  • typing
  • typing_extensions

Suppress an intentional direct import with a normal Flake8 suppression:

from package import Factory  # noqa: IMT001

Factory()

Compatibility and limitations

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.

Development

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.

Releasing

  1. Update the version in pyproject.toml and merge the change.
  2. Publish a GitHub Release whose tag is exactly v<version>, such as v0.1.0.
  3. Approve the protected pypi environment 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.

License

This project is distributed under the MIT License.

Metadata

Release files for flake8-import-type 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-import-type 0.1.0
File Size Uploaded
flake8_import_type-0.1.0.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-import-type 0.1.0
File Interpreter ABI Platform
flake8_import_type-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.7 kB

Release files / flake8_import_type-0.1.0.tar.gz

Download URL flake8_import_type-0.1.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e789e2e64beedd232fb757bcaea1366081e5456509571d935d8c14a157e9005b
BLAKE2b-256 checksum
How to use checksums
276834a3070c08f9711af94e283b4ff20fbcb340bbf34694ed1da8571c4a4e17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.

Transparency log

Release files / flake8_import_type-0.1.0-py3-none-any.whl

Download URL flake8_import_type-0.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9aa541a7a7819735af5121c700244ec9f8bd5ce900a6e13cd4c58f570648d34f
BLAKE2b-256 checksum
How to use checksums
9336489d1b6838f1d6ddaf64f25cce6ed596125b3dc07e6438725287d01d2f8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page