python / python/mypy

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

Aperta
#20,828 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug crash topic-protocols topic-recursive-types
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Nel report non sono identificati né un file sorgente né un percorso di test. Inizia con la riproduzione Protocol/TypeVar fornita, con numpy installato e i flag mypy indicati, quindi traccia il percorso di controllo che non termina; il lavoro è completato quando mypy completa l'elaborazione di questo input senza un uso sostenuto della CPU al 100% e la regressione è coperta da un test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
numpy, python
Ambito
devtools, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.