Class is not generic if it extends `type[X]`
@sobolevn ci sta già lavorando.
Dal 14/12/2022.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Code sample:
>>> from typing import TypeVar
>>> X = TypeVar('X')
>>> class Subtype(type[X]): ...
...
>>> Subtype[int]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: type 'Subtype' is not subscriptable
This is quite strange. To make it generic, you must have explicit Generic base class:
>>> from typing import Generic
>>> class Subtype(type[X], Generic[X]): ...
...
>>> Subtype[int]
__main__.Subtype[int]
It looks like a bug to me because of two reasons:
- Because other stdlib generics work differently:
>>> class Sublist(list[X]): ...
...
>>> Sublist[int]
- Because
typing.Typeworks as it should:
>>> from typing import Type
>>> class Subtype(Type[X]): ...
...
>>> Subtype[int]
__main__.Subtype[int]
But, I think that type is special enough to be handled extra carefully:
class S(type): ...is not generic and does not have__class_getitem__, hastypeinmroclass S(type[X]): ...is generic and has__class_getitem__, hastypeinmro
I can work on a fix if others agree that this is a bug 😊
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
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.
Altre issue di python/cpython
-
docs pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
build type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
stdlib topic-email type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Tutte le issue di python/cpython
Issue simili
-
link-check link-check:sphinx-theme
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
OpenHands/extensions#626 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
CSCfi/sd-search-api#39 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100