Flake8 Annotations is a plugin for Flake8 that enforces the presence and style of PEP 3107-style function annotations in Python code. It helps maintain consistent typing practices by flagging missing or incorrect type annotations. The current version is 3.2.0, and the project is actively maintained with regular updates addressing Python and Flake8 compatibility.
pip install flake8 flake8-annotationsVerified import paths — ran on the pinned version, not inferred.
Install flake8 and flake8-annotations. Create a Python file (e.g., `example.py`) with functions, some with and some without type annotations. Run `flake8 example.py` from your terminal to see the reported issues regarding missing annotations.
Ensure your project's `requires-python` is >=3.8.1 and `flake8` dependency is >=5.0. Version 3.2.0 further raised the Python requirement to >=3.10.
Migrate all type comments to PEP 526-style variable annotations (e.g., `def func(arg: str) -> None:`). Enable `ANN402` to detect lingering type comments: `flake8 --extend-select ANN402`.
To enable these warnings, use `flake8 --extend-select ANN401,ANN402` (or similar) in your command line or `extend-select = ANN401,ANN402` in your `pyproject.toml`, `setup.cfg`, or `.flake8` configuration file.
Use the `--allow-star-arg-any` flag (added in v2.9.0) to suppress `ANN401` specifically for `*args` and `**kwargs` annotations if this is an acceptable pattern in your codebase.
Enable the `--respect-type-ignore` flag (available since v3.1.0) to suppress linting errors for functions or modules annotated with `# type: ignore`. Module-level `# mypy: ignore-errors` or `# type: ignore` on the first line is also supported.