Clarification of `properly subclassable class` in NewType
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked NewType documentation section and reproduce the diagnostic using ObjectId. Clarify what “properly subclassable class” means and explain why ObjectId is reported as Any, then verify that the revised wording addresses the example and preserves the existing NewType guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100