[Python-ideas] Implement comparison operators for range objects
shibturn
shibturn at gmail.com
Thu Oct 13 20:16:47 CEST 2011
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
More information about the Python-ideas
mailing list