Severe performance degradation with lots of constrained type variables in a generic class
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report, To Reproduce, and Actual Behaviour
Mypy runs noticeably slower when analysing a class created from @dataclass or @dataclass_transform(), if the class is parameterised by constrained type variables. The increase in analysis time itself increases the more constrained type variables are added.
Upper-bounded type variables don't suffer this problem.
See mypy Playground, which fails with exit code 500. It isn't necessary to add fields on the class body, although it hits the performance problem with less type variables if you do. The snippet is roughly:
from typing_extensions import TypeVar, Generic
from dataclasses import dataclass
# Constrained
T1 = TypeVar("T1", int, None)
T2 = TypeVar("T2", int, None)
...
T20 = TypeVar("T20", int, None)
@dataclass
class A(Generic[T1, T2, ..., T20]):
pass
Expected Behavior
Is it sensible to expect performance to be similar to upper-bounded type variables?
Your Environment
- Mypy version used: 1.17.1
- Python version used: 3.11, 3.12
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il rallentamento nel mypy Playground collegato usando l’esempio di TypeVar vincolato, quindi confrontalo con la versione con limite superiore. Esamina il percorso di analisi per le classi dataclass o dataclass_transform e conferma il completamento quando molte variabili vincolate non causano più un tempo di analisi sproporzionato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100