[issue37807] Make hash() return a non-negative number

Tim Peters report at bugs.python.org
Sat Aug 10 14:33:42 EDT 2019


Tim Peters <tim at python.org> added the comment:

Well, I have no code that would benefit from this change.  What's the point?  Sure, I use _parts_ of hash codes at times, but, e.g.,

    index = the_hash_code & SOME_LOW_BIT_MASK
    
in Python couldn't care less about the sign of `the_hash_code` - it returns a non-negative int regardless.  The same applies if, e.g., SOME_LOW_BIT_MASK is `(1 << sys.hash_info.hash_bits) - 1`, giving a full-width non-negative hash without losing a bit of "entropy".  But I've never felt a need for the latter.  Likewise for doing, e.g.,

    index = the_hash_code % SOME_POSITIVE_PRIME

in Python.  % takes the sign (positive here) of the modulus in Python.

So this _looks_ like pointlessly disruptive code churn to me.  What killer use case am I missing?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37807>
_______________________________________


More information about the Python-bugs-list mailing list