python / python/mypy

Cannot instantiate Type[Type[...]]

オープン
#12,425 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature
主要言語
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()

Playground

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、報告されているクラス定義と type() の呼び出しを main.py に配置し、指定された Python 3.10 のセットアップで mypy を実行して診断を再現します。Type[Type[A]] の処理を追跡し、このケースを対象とするリグレッションテストを追加します。mypy がこの例を受け入れ、無関係なインスタンス化チェックを弱めていなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。