Message 63258 - Python tracker (original) (raw)
In 2.6a, seems like the hash implementation and eq must be defined together, in the same class. See also #1549. Ensuring that a hash implementation isn't being pulled from a builtin type is probably a sufficient check...?
class Base(object): ... def init(self, name): ... self.name = name ... def eq(self, other): ... return self.name == other.name ... def hash(self): ... return hash(self.name) ... class Extended(Base): ... def eq(self, other): ... print "trace: eq called" ... return Base.eq(self, other) ... hash(Base('b1')) 603887253 hash(Extended('e1')) Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'Extended'