Hash of None varies per-machine
Paul Rubin
http
Fri Apr 3 13:57:05 EDT 2009
ben.taylor at email.com writes:
> 1. Is it correct that if you hash two things that are not equal they
> might give you the same hash value?
Yes, hashes are 32 bit numbers and there are far more than 2**32
possible Python values (think of long ints), so obviously there must
be multiple values that hash to the same slot.
> 2. Should the hash of None vary per-machine?
If the docs say this shouldn't happen, then it's a bug. Otherwise,
it should probably be considered ok.
> 3. Given that presumably not all things can be hashed (since the
> documentation description of hash() says it gives you the hash of the
> object "if it can be hashed"), should None be hashable?
Yes, anything that can be used as a dict key (basically all immutable
values with equality comparison) should be hashable.
More information about the Python-list
mailing list