[Python-Dev] 2.5 status

Nick Coghlan ncoghlan at gmail.com
Mon Aug 7 17:05:52 CEST 2006


Martin v. Löwis wrote:
> tanzer at swing.co.at schrieb:
>>         >>> class X(object):
>>         ...   def __hash__(self): return id(self)
>>         ...
>>         >>> hash (X())
>>         Traceback (most recent call last):
>>           File "<stdin>", line 1, in <module>
>>         OverflowError: long int too large to convert to int
> 
> Yes, this comes from id() now always returning positive integers,
> which might be a long if the object pointer is > MAXINT
> 
> I think both instance_hash and slot_tp_hash should be changed
> to just truncate long ints to the range LONG_MIN..LONG_MAX

Couldn't they be changed to invoke long's own hash method when a long object 
is returned from __hash__?

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list