4 ms·
This kind of abuse is also available in Python! In [3]: class TheObjectThatIsEqualToAnything(object): def __eq__(self, other): retu
by gcr 13y ago
This kind of abuse is also available in Python!
In [3]:
class TheObjectThatIsEqualToAnything(object):
def __eq__(self, other):
return True
In [4]:
x = TheObjectThatIsEqualToAnything()
In [6]:
x == 3 and x == 5
Out [6]:
True
- Grue3 13y agoIt's not necessarily abuse. I once had to code a dummy object that supported all arithmetic operations with normal numbers and had a special comparison logic that it is never equal to itself. Then you could test if something is a number or a dummy object by comparing it to itself.