Clarification of `properly subclassable class` in NewType
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la sezione collegata della documentazione di NewType e riproduci la diagnostica usando ObjectId. Chiarisci cosa significa “classe correttamente sottoclassabile” e spiega perché ObjectId viene segnalato come Any, quindi verifica che la formulazione rivista affronti l’esempio e mantenga le indicazioni esistenti su NewType.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100