Class is not generic if it extends `type[X]`
@sobolevn がすでに取り組んでいます。
2022年12月14日 から。
評価
この issue はまだ評価されていません。
説明
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 😊
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
🐛 Bug 🔔 Pending processing
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
modelscope/DiffSynth-Studio#1702 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·