Annotations for `__eq__`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 302
- Ø Merge
- 23 Std.
- Gemergte PRs (30 T.)
- 8
Beschreibung
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.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der Lektüre der Typing-Spezifikation und des verknüpften discuss.python.org-Threads, um die bestehende Behandlung von eq zu verstehen. Die Arbeit ist abgeschlossen, wenn die Spezifikation abgestimmte Leitlinien für Vergleiche ohne Überschneidung, Rückgaben ohne booleschen Wert, NotImplemented und Fehler enthält, sodass Bibliotheksautoren sie konsistent anwenden können.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100