python / python/mypy

Clarification of `properly subclassable class` in NewType

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

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

bug documentation false-positive priority-1-normal topic-newtype
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

I want to create a new type derived from ObjectId in similar way as is described in documentation for new type UserId derived from int:

from bson import ObjectId
UserId = NewType('UserId', ObjectId)

But Mypy gives Argument 2 to NewType(...) must be subclassable (got "Any").

There is written in documentation:

NewType accepts exactly two arguments. The first argument must be a string literal containing the name of the new type and must equal the name of the variable to which the new type is assigned. The second argument must be a properly subclassable class, i.e., not a type construct like Union, etc.

It is not clear what properly subclassable class means and why ObjectId is not properly subclassable class. Could please someone clarify this to me and in documentation?

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

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

はじめの一歩

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

調査の方向性

リンク先のNewTypeドキュメントのセクションから始め、ObjectIdを使って診断を再現してください。「適切にサブクラス化可能なクラス」が何を意味するのかを明確にし、ObjectIdがAnyとして報告される理由を説明してください。そのうえで、改訂された文言が例に対応し、既存のNewTypeに関するガイダンスを維持していることを確認してください。

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

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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