python / python/mypy

Daemon crashes with a decorator returning `Generic/Protocol`, decorated method returning `Self`, and an undefined symbol

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

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

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

説明

Crash Report & To Reproduce

With a relatively simple reproducer and small example, this causes a crash. Anything larger than a small example will cause dmypy to hang.

  1. Set up the following dummy project
  2. cd project
  3. dmypy run
  4. Change project/src/pkg/utils.py (e.g. add a = 1234 at the end of this file)
  5. dmypy run again (crashes)

Dummy project:

project/
    src/
        pkg/
            __init__.py (blank)
            module.py
            utils.py
    mypy.ini
  • mypy.ini

    [mypy]
    files = src/
    
  • module.py

    from typing_extensions import Self
    from pkg.utils import deco
    
    var = UNDEFINED_SYMBOL
    
    class A:
        @deco
        def mymethod(self) -> Self: ...
    
  • utils.py

    from collections.abc import Callable
    from typing import Protocol, TypeVar
    from typing_extensions import ParamSpec
    
    _P = ParamSpec("_P")
    _R_co = TypeVar("_R_co", covariant=True)
    _T = TypeVar("_T")
    
    def deco(f: Callable[_P, _T], /) -> _Method[_P, _T]: ...
    
    class _Method(Protocol[_P, _R_co]): ...
    

Traceback

Runtime error from non-compiled mypy is below on master (commit https://github.com/python/mypy/commit/842a8fdcaa711c92c1067d373098844eb7d1ab57)

Daemon crashed!
Traceback (most recent call last):
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 237, in serve
    resp = self.run_command(command, data)
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 286, in run_command
    ret = method(self, **data)
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 354, in cmd_run
    return self.check(sources, export_types, is_tty, terminal_width)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 433, in check
    messages = self.fine_grained_increment_follow_imports(
        sources, explicit_export_types=export_types
    )
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 640, in fine_grained_increment_follow_imports
    messages = fine_grained_manager.update(changed, [], followed=True)
  File ".../python3.13/site-packages/mypy/server/update.py", line 286, in update
    changed_modules = propagate_changes_using_dependencies(
        self.manager,
    ...<5 lines>...
        self.processed_targets,
    )
  File ".../lib/python3.13/site-packages/mypy/server/update.py", line 857, in propagate_changes_using_dependencies
    raise RuntimeError("Max number of iterations (%d) reached (endless loop?)" % MAX_ITER)
RuntimeError: Max number of iterations (1000) reached (endless loop?)

Your Environment

  • Mypy version used: 1.18.2, master
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.13
  • Operating system and version: Pop OS! 22.04 LTS

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

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

はじめの一歩

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

調査の方向性

まず、提供されたダミープロジェクトを dmypy で実行し、次に mypy/dmypy_server.py と mypy/server/update.py の traceback のパスを調べます。特に、インクリメンタルな依存関係の伝播を確認してください。utils.py を変更した後の 2 回目の dmypy 実行を再現します。daemon がクラッシュもハングもせず、チェックが正常に完了すれば完了です。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
42/100

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

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