python / python/mypy

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

Offen
#20,828 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug crash topic-protocols topic-recursive-types
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Im Bericht ist keine Quelldatei oder kein Testpfad angegeben. Beginne mit der bereitgestellten Protocol/TypeVar-Reproduktion, mit installiertem numpy und den aufgeführten mypy-Flags, und verfolge dann den Prüfpfad, der nicht terminiert; fertig ist die Aufgabe, wenn mypy diese Eingabe ohne anhaltende 100% CPU-Auslastung verarbeitet und die Regression durch einen Test abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
numpy, python
Bereich
devtools, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.