[pypy-issue] Issue #2826: Tuple hash inconsistent when used with struct.unpack_from (pypy/pypy)

drwaopfer issues-reply at bitbucket.org
Tue May 8 16:57:41 EDT 2018


New issue 2826: Tuple hash inconsistent when used with struct.unpack_from
https://bitbucket.org/pypy/pypy/issues/2826/tuple-hash-inconsistent-when-used-with

drwaopfer:

Found a divergence from CPython: some tuples of integers that compare equal won't hash the same. Caused when some of the integers come from `struct.unpack_from`. I found this when my application unpacked values from a msgpack payload. I distilled my scenario into a minimal testcase below.

```python
import struct

packed = b"\x92\xcfp\x91|\x8b\x13n\xf8\xd0\x00"
regular_version = (8111401340639312080, 0)
p_up_version = (struct.unpack_from(">Q", packed, 2)[0], packed[10])
print(regular_version, "==" if regular_version == p_up_version else "!=", p_up_version)
print(
    hash(regular_version),
    "==" if hash(regular_version) == hash(p_up_version) else "!=",
    hash(p_up_version),
)
```

```
$ python --version
Python 3.5.5 :: Anaconda, Inc.
$ python testcase.py 
(8111401340639312080, 0) == (8111401340639312080, 0)
-4258064001062497448 == -4258064001062497448
$ pypy3 --version
Python 3.5.3 (fdd60ed87e94, Apr 24 2018, 06:10:04)
[PyPy 6.0.0 with GCC 6.2.0 20160901]
$ pypy3 testcase.py             
(8111401340639312080, 0) == (8111401340639312080, 0)
7271147797421229587 != -4258064001062497448
```




More information about the pypy-issue mailing list