为什么__hash__在提供__eq__时不会被继承?

时间:2016-10-21 22:55:53

标签: python python-3.x inheritance hash python-2.x

以下代码在python 2.7中有效,但在python 3.5中失败:

class Base(object):
    def __hash__(self):
        return 4

class Derived(Base): pass

class DerivedEquatable(Base):
    def __eq__(self, other):
        return False

assert Base.__hash__ is not None
assert Derived.__hash__ is not None
assert DerivedEquatable.__hash__ is not None  # AssertionError in python 3

此行为更改记录在哪里?

0 个答案:

没有答案