Consider an `__eq__` that always raises as non-overlapping for equality purposes?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
When a class defines __eq__, Mypy understandably bails out of ever considering that class as statically non-overlapping with another.
IOW,
class A:
pass
class B:
pass
A() == B()
goes error: Non-overlapping equality check (left operand type: "A", right operand type: "B") [comparison-overlap], as you'd expect, but
class A:
def __eq__(self, other: object) -> bool:
raise RuntimeError("Please do not directly compare A objects; use special method önnönnöö()")
def önnönnöö(self, other: A | B) -> bool:
return False # some specific Explicit Is Better Than Implicit logic here
class B:
pass
A() == B()
has no errors mypy could see.
It would be useful if mypy could recognize that an __eq__ function that always raises (or, I suppose, more broadly, can never return a value) makes a class never overlap with any other class.
Beitragsleitfaden
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
Das Issue betrifft mypys comparison-overlap-Diagnose und die Behandlung von Python-eq. Beginne damit, die Implementierung und Tests für comparison-overlap zu finden, und untersuche dann, wie ein eq, das immer eine Ausnahme auslöst, erkannt werden könnte. Als erledigt gilt die Aufgabe, wenn das gezeigte A- und B-Beispiel als Gleichheitsprüfung ohne Überschneidung behandelt wird, ohne bestehende Diagnosen abzuschwächen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100