Skip to main content

A flake plugin that checks for typing.TYPE_CHECKING-able imports

Project description

A plugin for flake8 that checks your code for imports that are only used in annotations. These imports can then be moved under an if typing.TYPE_CHECKING: block to prevent them being imported at runtime. This can minimise the number of runtime dependencies that your modules have and perhaps also reduce the likelyhood of a circular import.

For example:

import dataclasses
import datetime

@dataclasses.dataclass
class Person:
    name: str
    birthday: datetime.date

The above code will emit a lint (code: TCI100) telling you that it can be converted to this:

import dataclasses
import typing

if typing.TYPE_CHECKING:
    import datetime

@dataclasses.dataclass
class Person:
    name: str
    birthday: datetime.date

You can install the latest version from pypi using pip like so:

pip install flake8-typechecking_import

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8_typechecking_import-0.5.tar.gz (16.3 kB view hashes)

Uploaded Source

Built Distribution

flake8_typechecking_import-0.5-py3-none-any.whl (15.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page