python / python/typing

Annotations for `__eq__`

Offen
#1,536 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

topic: documentation topic: typing spec
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

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Ö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

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.