[docs] [issue18440] hash() and __hash__() do not document their size constraints
Barry A. Warsaw
report at bugs.python.org
Sat Jul 13 20:34:45 CEST 2013
New submission from Barry A. Warsaw:
If you have a custom object that implements __hash__() and it returns a value wider than Py_ssize_t, built-in hash() on the object will truncate information. This is because hash() takes the value returned by obj.__hash__() and coerces it through PyLong_FromSsize_t(). This can cause object hashes to have different values on 64bit and 32bit machines, e.g. on 64bit Linux where Py_ssize_t is 8 bytes wide vs. 32bit Linux where it is 4 bytes wide.
This may be perfectly reasonable from an implementation point of (ref: issue9778) but it is surprising since it is not documented.
This size constraint on object hashes should be documented.
from ctypes import *
---64bit Ubuntu 13.10---
$ python3.3 hashex.py
---32bit Ubuntu 13.10---
$ python3 hashex.py
assignee: docs at python
nosy: barry, docs at python
title: hash() and __hash__() do not document their size constraints
versions: Python 3.2, Python 3.3, Python 3.4
Python tracker <report at bugs.python.org>
More information about the docs