Cannot instantiate Type[Type[...]]
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
Mypy thinks that Type[Type[...]] cannot be instantiated. I understand that it can be difficult to support, but is there any reason to consider it an error?
Type[Type[something]] is type or its subclass. It can be instantiated (code below runs without errors).
To Reproduce
Write the following code, run mypy on it.
class A:
pass
B = type(A)('B', (A,), {})
b = B()
Expected Behavior
No errors (but I'm not sure that I'm not just missing something and under certain circumstances such code can be incorrect).
Actual Behavior
mypy reports:
main.py:4: error: Cannot instantiate type "Type[Type[A]]"
Your Environment
- Mypy version used: 0.941 latest (from pip & playground)
- Mypy command-line flags: nothing
- Mypy configuration options from
mypy.ini(and other config files): nothing - Python version used: 3.10
- Operating system and version: Ubuntu 22.04
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、報告されているクラス定義と type() の呼び出しを main.py に配置し、指定された Python 3.10 のセットアップで mypy を実行して診断を再現します。Type[Type[A]] の処理を追跡し、このケースを対象とするリグレッションテストを追加します。mypy がこの例を受け入れ、無関係なインスタンス化チェックを弱めていなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100