`type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
指定された mypy コマンドと opentelemetry のインポートを使用して file.py で交互に変化する結果を再現し、その後 unused-ignore の状態に関するキャッシュ関連の処理を追跡します。キャッシュされた状態での実行を繰り返す回帰テストを追加します。完了の条件は、コマンドが一貫して不要な [unused-ignore] エラーを報告しないことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100