-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
Description
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.