Alias that is generic over a ParamSpec cannot be further specialized
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
A type alias that is generic over a ParamSpec can be specialized with a list of types, and if this list includes a TypeVar, the resulting alias is still generic to type checkers, but it cannot be subscripted again at runtime.
>>> from collections.abc import Callable
>>> type X[**P] = Callable[P, int]
>>> T = TypeVar("T")
>>> X[[T]]
X[[~T]]
>>> X[[T]][str]
Traceback (most recent call last):
File "<python-input-14>", line 1, in <module>
X[[T]][str]
~~~~~~^^^^^
TypeError: X[[~T]] is not a generic class
Pyright accepts this code, and I think it's right: https://pyright-play.net/?strict=true&code=GYJw9gtgBAxmA28CmMAuBLMA7AzgOgEMAjGKdCABzBFSgGEDFjkAoUSKVATwvSwHMylarQAqPJADUCIFi1FQAvFHEUpMgBQAiUVoCUc7mqgANANoAqCwAUAukvqN4zJGesAaMllS2WJhcrmZqK2viwAJkjAUMAaAB4AXKaiZjioILZ6CSxQuVAgSABuSIwA%2BkZI8Xq5AMRQGmkg1QC0AHxeqCxAA
Reported by @Daraan in https://github.com/python/typing_extensions/pull/449/files#r1771594266.
I believe this could be fixed by making _Py_make_parameters in genericaliasobject.c recurse into lists.
Linked PRs
- gh-124512
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
Leggi _Py_make_parameters in genericaliasobject.c e riproduci il fallimento X[[T]][str] riportato nell’issue. Controlla il lavoro collegato gh-124512 prima di iniziare. Il lavoro è completato quando un alias specializzato con una lista contenente un TypeVar può essere nuovamente indicizzato a runtime senza generare un TypeError.
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
- 35/100