python / python/mypy

dmypy's `--use-fine-grained-cache` crashes with `KeyError` on namespace packages

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

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

crash topic-daemon
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

This is possibly related to #10735.

To Reproduce & Traceback

Create a minimal project as follows:

project/
  mypy.ini
      [mypy]
      files = src/
  src/
    pkg/
      __init__.py
      nspkg/
        mod.py
            a: int = ""

Reproduce with these steps:

  1. Navigate to project/
  2. $ mypy --cache-fine-grained
    src/pkg/nspkg/mod.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
    
  3. $ dmypy run -- --use-fine-grained-cache
    Daemon started
    Success: no issues found in 2 source files
    
    (I don't think this should say Success given the errors from Step 2., but that's a separate issue.)
  4. Change mod.py, e.g. modify the sole line to a: int = "a"
  5. Run the daemon twice:
    • $ dmypy run -- --use-fine-grained-cache
      src/pkg/nspkg/mod.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
      
    • $ dmypy run -- --use-fine-grained-cache
      Daemon crashed!
      Traceback (most recent call last):
        File ".../mypy/dmypy_server.py", line 237, in serve
          ...
        File ".../mypy/dmypy_server.py", line 768, in find_reachable_changed_modules
       worklist.append(BuildSource(graph[dep].path, graph[dep].id, followed=True))
                                   ~~~~~^^^^^
      KeyError: 'pkg.nspkg'
      

Your Environment

  • Mypy version used: 1.19.1
  • Python version used: Python 3.13

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

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

はじめの一歩

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

調査の方向性

dmypy と --use-fine-grained-cache を使って namespace package のケースを再現し、その後、find_reachable_changed_modules と 768 行目の周辺にある dmypy_server.py を調べます。ここでは traceback が graph 内で pkg.nspkg を検索しています。記載されているコマンドを使って、2 回目の実行で daemon がクラッシュしなくなり、引き続き代入エラーが報告されることを確認します。

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

評価

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

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

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