flake8-pep585
raw JSON → 0.1.7 verified Fri May 01 auth: no python
A flake8 plugin that enforces the use of new-style type hints as specified in PEP 585 (e.g., list[str] instead of typing.List[str]). Current version 0.1.7 supports Python 3.7+ with configurable activation on older versions. Released periodically.
pip install flake8-pep585 Common errors
error ModuleNotFoundError: No module named 'flake8_pep585' ↓
cause The plugin is installed but users try to import it directly as a Python module.
fix
Do not import flake8_pep585 directly; it is a flake8 plugin. Run flake8 with the plugin installed and ensure require-plugins is set.
error PEP 585: Use new-style type hint '...' instead of 'typing...' ↓
cause The plugin correctly flags old-style type hints (e.g., typing.List) that should be replaced with built-in generics (e.g., list).
fix
Change typing.List[int] to list[int], typing.Dict[str, int] to dict[str, int], etc.
Warnings
gotcha The plugin only works when flake8 is invoked with the '--require-plugins=flake8-pep585' flag or a compatible configuration if using flake8>=6.0. ↓
fix Run flake8 with '--require-plugins=flake8-pep585' or configure 'require_plugins = flake8-pep585' in setup.cfg or .flake8.
gotcha On Python 3.7 and 3.8, the plugin is disabled by default unless 'from __future__ import annotations' is used. This can be confusing when running CI on multiple Python versions. ↓
fix Use '--pep585-activation=always' to force enable on Python 3.7/3.8, or add 'from __future__ import annotations' to files.
Imports
- flake8_pep585 wrong
from flake8_pep585 import *correctInstall via pip; no explicit import needed. Add '--require-plugins=flake8-pep585' to flake8 arguments if using flake8>=6.0.
Quickstart
pip install flake8 flake8-pep585
cat > test.py <<EOF
from typing import List
def foo() -> List[int]:
return [1, 2]
EOF
flake8 test.py