https://github.com/ofekshilon/flake8_typing_imports
Flake8 extension that alerts on imports used only for typing
https://github.com/ofekshilon/flake8_typing_imports
flake8-extension flake8-plugin
Last synced: 2 days ago
JSON representation
Flake8 extension that alerts on imports used only for typing
- Host: GitHub
- URL: https://github.com/ofekshilon/flake8_typing_imports
- Owner: OfekShilon
- Created: 2025-03-08T16:59:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-08T20:16:13.000Z (about 1 year ago)
- Last Synced: 2025-12-26T01:56:34.500Z (4 months ago)
- Topics: flake8-extension, flake8-plugin
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```python
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 .
```
3. Finally, run flake8 in your preferred way, the simplest being:
```
$ flake8
```