python / python/mypy

`type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run

オープン
#20,105 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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)

  1. Run pip install opentelemetry-instrumentation-asgi opentelemetry-distro
  2. Add the code snippet below to file.py
  3. Run mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no error
  4. Run mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observe an [unused-ignore] error
  5. Run mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no error
  6. 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

指定された mypy コマンドと opentelemetry のインポートを使用して file.py で交互に変化する結果を再現し、その後 unused-ignore の状態に関するキャッシュ関連の処理を追跡します。キャッシュされた状態での実行を繰り返す回帰テストを追加します。完了の条件は、コマンドが一貫して不要な [unused-ignore] エラーを報告しないことです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。