In this example, I am trying to assign new __eq__, __lt__ and __gt__ methods and invoke them by comparing the object to the literal 3. Why is bar(...) never called?
class Foo:
def __init__(self):
self.__eq__ = self.bar
self.__lt__ = self.bar
self.__gt__ = self.bar
def bar(self, other):
print("bar called.")
a = Foo()
a == 3
a < 3
a > 3
In this answer I found the hint you can't assign new __eq__ to the object. I can't find any official source for this statement though.
Any hints and help is appreciated!
Edit: I am aware that there is the option of defining __eq__ in the object itself, but this questions is specifically about assigning it after instance creation.