flake8-pyi is a plugin for Flake8 that specializes in linting `.pyi` stub files. It enforces type-hinting best practices and adheres to the typeshed style guide, providing specific warnings (codes starting with Y0). The library is actively maintained, with frequent releases that often introduce new error codes and adapt to changes in Python's typing ecosystem. The current version is 25.5.0.
pip install flake8 flake8-pyiNo compatibility data collected yet for this library.
To use flake8-pyi, first install both `flake8` and `flake8-pyi`. Then, you can run `flake8` directly on your `.pyi` files or your project directory. flake8-pyi automatically applies its checks to `.pyi` files. Configuration, such as enabling disabled error codes or ignoring others, can be managed in a `pyproject.toml` (under `[tool.flake8]`), `setup.cfg`, `tox.ini`, or `.flake8` file.
Upgrade your Python environment to 3.9 or newer.
Run `flake8-pyi` in a dedicated environment (e.g., a separate CI job or virtual environment) to avoid conflicts with other `flake8` plugins that might not be `.pyi` file-aware.
Add `extend-select = Y090` to your `flake8` configuration file (e.g., `pyproject.toml`, `setup.cfg`).
Review and update `typing_extensions` imports in `.pyi` files, preferring `typing` where available and compatible with the target Python versions.
Periodically review the changelog for new error codes and adjust `flake8` configuration (e.g., `pyproject.toml`) accordingly.
Rename your `TypeVar`, `ParamSpec`, or `TypeVarTuple` to begin with an underscore, for example, `_T = TypeVar('_T')`.Replace `pass` with `...` in empty function or class bodies within your `.pyi` file.
Ensure that the body of any function in a stub file contains only `...`.
Replace `typing.Union[A, B]` with `A | B` and `typing.Optional[A]` with `A | None`.
Remove quotes from type annotations in your `.pyi` file (e.g., change `'ClassName'` to `ClassName`).