[Python-Dev] returning longs from __hash__()

Armin Rigo arigo at tunes.org
Tue Aug 8 12:26:08 CEST 2006


Hi all,

The 2.5 change of id() to return positive ints-or-longs is likely to
cause quite some breakage in user programs that erroneously implemented
custom __hash__() functions returning a value based on an id().  This
was discussed a few times already but it showed up again as a bug report
(#1536021).  Of course it has always been documented that id() is not
directly suitable as the return value of a custom __hash__(), but so far
it worked on 32-bit machines so people have been doing it all the time.

Maybe the user should just be able to return any integer value from a
custom __hash__() without having to worry about not exceeding
sys.maxint.

After all the returned value has no real meaning.  If a long is returned
we could take its hash again, and use that number internally.


A bientot,

Armin


More information about the Python-Dev mailing list