I have a containery object something like this:
class foo(object):
def __init__(self,value):
self.value = value
def __eq__(self,other):
return self.value == other
Which I can use like this:
>>> var = foo(4)
>>> var == 4
True
>>> var == 3
False
>>> # So far so good
>>> var == foo(4)
True
>>> var == foo(3)
False
>>> # Huh
My question is: what is happening that allows this to magically "just work"? How does Python bind the == operator inside __eq__ so that the value member of both sides is compared?
3 != 4?varis effectively4, so comparing it to anything other than4orfoo(4)should return False?