[PEP 696] `TypeError` when subclassing and omitting `TypeVar` with default.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
The following example raises a TypeError: Some type variables (T) are not listed in Generic[U]:
class Bar[T, S=T]: ...
class Baz[U](Bar[U]): ...
Full Traceback
Traceback (most recent call last):
File "/home/rscholz/Downloads/tmp.py", line 3, in <module>
class Baz[U](Bar[U]): ...
File "/home/rscholz/Downloads/tmp.py", line 3, in <generic parameters of Baz>
class Baz[U](Bar[U]): ...
File "/usr/lib/python3.13/typing.py", line 1288, in _generic_init_subclass
raise TypeError(f"Some type variables ({s_vars}) are"
f" not listed in Generic[{s_args}]")
TypeError: Some type variables (T) are not listed in Generic[U]
The PEP states that
non-overridden defaults should be substituted in, and type parameters with such defaults can be further specialised down the line.
And the typing spec uses similar phrasing, which makes me believe this is a bug. In the example above, I'd expect that Baz[U] is a Bar[U, U] by substitution + default.
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-155646
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 in /usr/lib/python3.13/typing.py, in _generic_init_subclass, dove viene sollevato il TypeError segnalato, e confronta il comportamento con le sezioni sull’ereditarietà di PEP 696 e della specifica di typing. Il lavoro è completato quando l’esempio mostrato Bar/Baz segue il comportamento documentato di sostituzione predefinita senza sollevare l’errore segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 20/100