flake8-typechecking-import 0.5


pip install flake8-typechecking-import

  Latest version

Released: Jun 11, 2021

Project Links

Meta
Author: Adrian Room
Requires Python: >3.6

Classifiers

License
  • OSI Approved :: GNU General Public License v3 or later (GPLv3+)

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
Extras:
Dependencies:
flake8
dataclasses