Skip to content

OfekShilon/flake8_typing_imports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

flake8_typing_imports

When an import is added only to satisfy static-analysis tools like mypy, pyright or pyre, it risks incurring redundant runtime overhead. The preferrable way to code such an import is:

from __future__ import annotations
from typing import TYPE_CHECKING
...

if TYPE_CHECKING:
  from my.module import MyAwesomeType


def func(input: MyAwesomeType):
  ...

This project is a flake8 extension that alerts on such imports, used only for typing, and suggests moving them to a TYPE_CHECKING block.

This won't be uploaded to PyPI until it gathers some more mileage. In the mean time, to use it:

  1. Clone the repo,
  2. From the repo directory:
$ pip install .
  1. Finally, run flake8 in your preferred way, the simplest being:
$ flake8 <path> 

About

Flake8 extension that alerts on imports used only for typing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages