mypy --warn-unused-ignores: Flag Stale Ignores
mypy --warn-unused-ignores reports any # type: ignore comment that is no longer suppressing an error.
Ignores accumulate. This flag keeps them honest by failing when one has become dead weight, which usually means the underlying error was fixed.
What it does
mypy --warn-unused-ignores emits a warning for every # type: ignore that does not actually suppress an error on its line. It is part of --strict. Combined with --warn-unused-ignores being treated as an error in CI, it forces stale ignores to be removed.
Common usage
mypy --warn-unused-ignores src/
# config form
# [tool.mypy]
# warn_unused_ignores = trueOptions
| Flag or key | What it does |
|---|---|
| --warn-unused-ignores | Warn on type:ignore comments that suppress nothing |
| warn_unused_ignores | Config key form (true/false) |
| # type: ignore[code] | Narrow ignores make unused detection precise |
In CI
An ignore can be needed on one mypy version and unused on another (different Python version targets change which errors fire). A matrix build can fail with "unused type: ignore" on one cell only. Pin the mypy and --python-version target so the ignore set is stable across the pipeline.
Common errors in CI
The message is "warning: unused 'type: ignore' comment". If it appears only on some matrix legs, the cause is a differing --python-version or platform changing which branch type-checks; align the target or scope the ignore with a code so it stays valid.