Inheritance - __hash__ sets to None in a subclass
问题 I managed to reproduce this on both Python 3.4 and 3.7. Consider: class Comparable: def _key(self): raise NotImplementedError def __hash__(self): return hash(self._key()) def __eq__(self, other): ... def __lt__(self, other): ... class A(Comparable): pass class B(A): def __str__(self): return "d" def __eq__(self, other): return isinstance(self, type(other)) def _key(self): return str(self), b = B() Clearly one would expect b.__hash__ to be defined here, since it is defined under Comparable