Annotations for `__eq__`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Descrizione
It would be useful to have more guidance on how __eq__ methods should be annotated.
A few considerations:
- Enable type checkers to warn on non-overlapping equality comparisons. The type annotations should ideally allow type checkers to look at a check like
A() == B()and verify whether it can ever return True. - Some level of support for
__eq__returning a non-boolean (classic example: numpy arrays) - How to think about
__eq__methods that return NotImplemented on unrecognized types versus those that throw an error
See also https://discuss.python.org/t/make-type-hints-for-eq-of-primitives-less-strict/34240
Covering this in the typing spec is important because it affects how library authors should annotate __eq__ methods in their libraries if they want all type checkers to understand these methods.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 leggendo la specifica di typing e la discussione collegata su discuss.python.org per comprendere il trattamento attuale di eq. Il lavoro sarà completo quando la specifica fornirà indicazioni condivise per i confronti non sovrapposti, i valori restituiti non booleani, NotImplemented e gli errori, in modo che gli autori delle librerie possano applicarle in modo coerente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 30/100