Generic subclass of a generic class, using a constrained TypeVar is mishandled
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
from typing import Generic, TypeVar
T = TypeVar("T")
N = TypeVar("N", int, float)
class C(Generic[T]):
def __init__(self, c: T):
self.c = c
class C2(C[N]):
def __init__(self, c: N):
super().__init__(c) # Unexpected error
results in an unexpected
error: Argument 1 to "__init__" of "C" has incompatible type "int"; expected "N" [arg-type]
error: Argument 1 to "__init__" of "C" has incompatible type "float"; expected "N" [arg-type]
on the last line of the test file.
Your Environment
Confirmed with mypy 1.11.2 in Python 3.11.9, without any flags; does not seem version-specific.
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
Inizia riproducendo lo snippet segnalato con mypy 1.11.2 su Python 3.11.9, senza flags, e analizza la gestione del TypeVar vincolato N nella sottoclasse generica e nella chiamata a super().init. Il lavoro è completato quando l’esempio non emette più i due errori arg-type imprevisti, mantenendo al contempo il controllo dei tipi generico previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100