Skip to content

Clarification of properly subclassable class in NewType #6701

@hmoravec

Description

@hmoravec

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions