New submission from jason kirtland: 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 "<stdin>", line 1, in <module> TypeError: unhashable type: 'Extended' ---------- components: Interpreter Core messages: 63258 nosy: jek severity: normal status: open title: __eq__ / __hash__ check doesn't take inheritance into account type: crash versions: Python 2.6 __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2235> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com