13 Oct
2011
13 Oct
'11
6:16 p.m.
On 13/10/2011 6:30pm, Guido van Rossum wrote:
(Note: __hash__ needs to create equivalence classes that are proper extensions of those created by __eq__. In terms of the Wikipedia picture, an extension is allowed to merge some equivalence classes but not to split them.)
Actually cpython's dict lookup does not check equivalence of keys using __eq__ directly. Instead it uses something similar to def eq(a, b): return a.__hash__() == b.__hash__() and a.__eq__(b) This ensures compatibility with the equivalence classes for __hash__. (It is also an optimisation.) Cheers, sbt