Bug Report
When running mypy with --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports, putting a type: ignore[attr-defined] on an import will have mypy report an Unused "type: ignore" comment [unused-ignore] every other run, unless the cache is being cleared between runs.
To Reproduce
from opentelemetry.instrumentation.asgi import ( # type: ignore[attr-defined]
OpenTelemetryMiddleware,
)
(Since this only seems to work with external packages, some setup is required)
- Run
pip install opentelemetry-instrumentation-asgi opentelemetry-distro
- Add the code snippet below to
file.py
- Run
mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no error
- Run
mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observe an [unused-ignore] error
- Run
mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no error
- Repeat the cycle as many times as you like :)
When removing the cache between runs, all works well, so I suspect it has something to do with caching.
Your Environment
- Mypy version used:
1.18.2, main
- Mypy command-line flags:
--warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports
- Mypy configuration options from
mypy.ini (and other config files): -
- Python version used: 3.13.7
Bug Report
When running mypy with
--warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports, putting atype: ignore[attr-defined]on an import will have mypy report anUnused "type: ignore" comment [unused-ignore]every other run, unless the cache is being cleared between runs.To Reproduce
(Since this only seems to work with external packages, some setup is required)
pip install opentelemetry-instrumentation-asgi opentelemetry-distrofile.pymypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no errormypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observe an[unused-ignore]errormypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no errorWhen removing the cache between runs, all works well, so I suspect it has something to do with caching.
Your Environment
1.18.2,main--warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-importsmypy.ini(and other config files): -