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.3

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.3
File Size Uploaded
flake8_import_type-0.1.3.tar.gz 11.1 kB Details

Built distribution (wheel)

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

Total release size: 18.9 kB

Release files / flake8_import_type-0.1.3.tar.gz

Download URL flake8_import_type-0.1.3.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a680c6d88654fedfc8aa4dbad36d29162a523a225e2fb5e75562935cb9b05e34
BLAKE2b-256 checksum
How to use checksums
dfefea0f49a27ee5f063b88b7b80987e21b4719421d177c62287c22c8f13efa0
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 Oct 5, 2026.

Transparency log

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

Download URL flake8_import_type-0.1.3-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2418ed1c51c7c0dd17a1fbaf1f18083b4e6a6f909b1086f72dc7a9d1d7966b4
BLAKE2b-256 checksum
How to use checksums
cbb5b54ba85e507ee3e816b94c1b8f98e2af7cafc811de992141aae26a226af0
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 Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.0

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