Python は比較演算子の左/右バージョンを提供しないため、どの関数を呼び出すかをどのように決定するのでしょうか?
class A(object):
def __eq__(self, other):
print "A __eq__ called"
return self.value == other
class B(object):
def __eq__(self, other):
print "B __eq__ called"
return self.value == other
>>> a = A()
>>> a.value = 3
>>> b = B()
>>> b.value = 4
>>> a == b
"A __eq__ called"
"B __eq__ called"
False
これは両方の__eq__
関数を呼び出すようです。
公式の決定木を探しています。