[issue8188] Unified hash for numeric types.

Mark Dickinson report at bugs.python.org
Tue Mar 23 15:01:34 CET 2010


Mark Dickinson <dickinsm at gmail.com> added the comment:

Another update, partly to address comments raised by Guido on Rietveld.  I'll upload these changes to Rietveld later today.

 - rename sys._hash_info to sys.hash_info and make it public rather than private (it still needs docs somewhere)

 - add some explanatory comments to long_hash; remove an outdated comment

 - fix missing error check (in previous patch) in slot_tp_hash.  slot_tp_hash also now always raises a TypeError if __hash__ returns a non-integer;  this is a change from current behaviour, which allows small floats to be returned by __hash__, but not large floats (where large means > 2**31 or > 2**63 in absolute value, depending on the system).  I'm assuming this was unintentional (the docs specify that __hash__ should return an integer).

 - simplify specification of hash function slightly:  for nonnegative x it simply computes the reduction of x;  previously it computed 1 + reduction of (x-1) for positive values.  This extra +-1 doesn't really add anything of value, and makes it slightly more complicated and error-prone to write your own hash function.

----------
Added file: http://bugs.python.org/file16629/numeric_hash4.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8188>
_______________________________________


More information about the Python-bugs-list mailing list