Greg Ewing wrote:
Nick Coghlan wrote:
Objects which compare equal must also end up in the same hash bucket
in order for dictionaries to work correctly.
And, if its equality with another object can change during
its lifetime, it will never work properly in a dictionary.
So in that case you should leave __hash__ unimplemented so
that you can't accidentally use one as a dict key.
As of 2.6b2 (and 3.0b2) you can actually set "__hash__ = None" to
explicitly block the inheritance of the method in a new-style class and
have Python correctly consider the type unhashable even though it has a
__hash__ attribute.
Making object.__hash__ inherited by default again in 2.6 while still
preserving useful behaviour for the collections.Hashable ABC turned out
to be a fairly interesting exercise...
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com