python / python/mypy

Runs forever at 100% CPU for generic protocol with bounded TypeVar argument

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

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

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

説明

Bug Report

This makes mypy run forever at 100% CPU.

Note that numpy must be installed, else mypy returns immediately (I guess it thinks np.float64 = Any).

I cannot reproduce if I remove any of the methods or replace np.float64 with float or str.

To Reproduce

from __future__ import annotations


from typing import Protocol, TypeVar


import numpy as np


I = TypeVar("I")


float_bound = TypeVar('float_bound', bound=float)
float_bound_2 = TypeVar('float_bound_2', bound=float)


class Container(Protocol[I]):

    def __abs__(self: Container[float_bound]) -> Container[float_bound]:
        ...

    def __rmul__(self: Container[float_bound], other: np.float64 | Container[float_bound_2], /) -> Container[float_bound | float_bound_2]:
        ...

    def __rtruediv__(self: Container[float_bound], other: np.float64 | Container[float_bound_2], /) -> Container[float_bound | float_bound_2]:
        ...

    def __sub__(self: Container[float_bound], other, /) -> Container[float_bound]:
        ...

    def __truediv__(self: Container[float_bound], other: np.float64 | Container[float_bound_2], /) -> Container[float_bound | float_bound_2]:
        ...

Actual Behavior

mypy prints no output, it runs forever at 100% CPU (PC fans constantly spinning).

Your Environment

Debian 13, with python3-numpy 1:2.2.4+ds-1

  • Mypy version used: both 1.15 from the Debian 13 repo and 1.19.1 from the Debian sid repo. I'm told this happens since mypy 1.9 or older, but I do not have the VM to confirm personally.
  • Mypy command-line flags: --ignore-missing-imports --check-untyped-defs --no-error-summary --no-implicit-reexport --pretty --strict-equality
  • Mypy configuration options from mypy.ini (and other config files): these files do not exist
  • Python version used: 3.13.5. I'm told this happened on older Python versions, but I do not have the VM to confirm personally.

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

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

はじめの一歩

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

調査の方向性

報告ではソースファイルもテストパスも特定されていません。numpyをインストールし、記載されたmypyフラグを指定したうえで、提供されたProtocol/TypeVarの再現から始め、その後、終了しないチェック経路を追跡してください。完了の条件は、mypyがこの入力をCPU使用率100%の状態が持続することなく完了し、回帰がテストでカバーされていることです。

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

評価

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

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

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