Overloads in generic classes are extremely slow when using generic self
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Performance of mypy degrades drastically with the number of type variable constraints when checking overloaded method of generic class with overloaded self.
To Reproduce
from typing import TypeVar, Generic, TypeAlias, overload, Any
T1 = TypeVar('T1', int, str, bool)
T2 = TypeVar('T2', int, str, bool)
T3 = TypeVar('T3', int, str, bool)
T4 = TypeVar('T4', int, str, bool)
T5 = TypeVar('T5', int, str, bool)
T6 = TypeVar('T6', int, str, bool)
T7 = TypeVar('T7', int, str, bool)
class A(Generic[T1, T2, T3, T4, T5, T6, T7]):
@overload
def foo(self: A[int, T2, T3, T4, T5, T6, T7]) -> int:
...
@overload
def foo(self: A[str, T2, T3, T4, T5, T6, T7]) -> str:
...
def foo(self) -> int | str:
raise NotImplementedError
https://mypy-play.net/?mypy=latest&python=3.12&gist=fd939322936206cbb9b1f45a71fbd9b7
Expected Behavior
Code typechecks in realistic time. For reference pyrights checks such code without significant performance issues
Actual Behavior
mypy-play.net times out. In my experience it takes at least more than 10 minutes to check such code. Interestingly, when converting foo method to an independent function taking A as a parameter typechecking time drops significantly.
Your Environment
python3.11 and python3.12, both mypy 1.12.1 and 1.13
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der bereitgestellten Python-Reproduktion und dem mypy-play-Link und vergleiche anschließend deren Prüfzeit mit der im Bericht beschriebenen Variante mit unabhängiger Funktion. Miss, wie sich die Laufzeit verändert, wenn die Anzahl der eingeschränkten Typvariablen steigt, und verwende das erwartete Verhalten – die Typprüfung in realistischer Zeit – als Abschlusskriterium.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100