equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Jun 28 23:47:16 EDT 2007
En Thu, 28 Jun 2007 11:38:56 -0300, A.T.Hofkamp <hat at se-162.se.wtb.tue.nl>
escribió:
> The point I intended to make was that having a default __hash__ method on
> objects give weird results that not everybody may be aware of.
> In addition, to get useful behavior of objects in sets one should
> override
> __hash__ anyway, so what is the point of having a default
> object.__hash__ ?
__hash__ and equality tests are used by the dictionary implementation, and
the default implementation is OK for immutable objects. I like the fact
that I can use almost anything as dictionary keys without much coding.
This must always be true: (a==b) => (hash(a)==hash(b)), and the
documentation for __hash__ and __cmp__ warns about the requisites (but
__eq__ and the other rich-comparison methods are lacking the warning).
--
Gabriel Genellina
More information about the Python-list
mailing list