homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jek
Recipients jek
Date 2008年03月04日.19:49:23
SpamBayes Score 0.21306306
Marked as misclassified No
Message-id <1204660164.8.0.960033908954.issue2235@psf.upfronthosting.co.za>
In-reply-to
Content
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'
History
Date User Action Args
2008年03月04日 19:49:25jeksetspambayes_score: 0.213063 -> 0.21306306
recipients: + jek
2008年03月04日 19:49:24jeksetspambayes_score: 0.213063 -> 0.213063
messageid: <1204660164.8.0.960033908954.issue2235@psf.upfronthosting.co.za>
2008年03月04日 19:49:23jeklinkissue2235 messages
2008年03月04日 19:49:23jekcreate

AltStyle によって変換されたページ (->オリジナル) /