Hacker News new | ask | show | jobs
by gcr 4447 days 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
1 comments

It'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.