class L(object):
def __eq__(self, other):
print 'invoked L.__eq__'
return False
class R(object):
def __eq__(self, other):
print 'invoked R.__eq__'
return False
left = L()
right = R()
使用这段代码,左侧首先进行比较,根据数据模型所记录:
>>> left == right
invoked L.__eq__
False
但是,如果我们对第6行进行轻微修改(其他不变):
class R(L):
现在轮到右侧先进行比较。
>>> left == right
invoked R.__eq__
False
为什么这样设计?在哪里有记录,设计决策的理由是什么?