hashkey/digest for a complex object
hniksic at xemacs.org
Sun Oct 10 18:24:21 CEST 2010
Arnaud Delobelle <arnodel at gmail.com> writes:
> I have learnt too that hash(-1) is not (-1), and that it seems that a
> hash value is not allowed to be (-1). There is one thing left to find
> out. Why can't it be (-1)?
Because -1 has a special meaning in the C function equivalent to
Python's hash(). PyObject_Hash returning -1 means that an exception was
raised somewhere inside the object's __hash__ method. For that reason
hash functions that really return -1 must change that to another value,
and -2 is as good a replacement as any.
This is documented in
More information about the Python-list