`type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run
未关闭
还没有人认领这个 Issue。
bug
topic-configuration
topic-incremental
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用列出的 mypy 命令和 opentelemetry 导入,通过 file.py 重现交替结果,然后追踪与 unused-ignore 状态相关的缓存处理。为重复的缓存运行添加回归测试;当该命令始终不报告无端的 [unused-ignore] 错误时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100