Author: p_ziesch...@yahoo.de Branch: ep2016sprint Changeset: r85827:0888d83c7222 Date: 2016-07-23 15:54 +0200 http://bitbucket.org/pypy/pypy/changeset/0888d83c7222/
Log: Issue #2346 : Hashing of -1 did not return -2 as cpython diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py --- a/pypy/objspace/std/specialisedtupleobject.py +++ b/pypy/objspace/std/specialisedtupleobject.py @@ -62,6 +62,11 @@ value = getattr(self, 'value%s' % i) if typetuple[i] == object: y = space.int_w(space.hash(value)) + elif typetuple[i] == int: + # mimic cpythons behavior of a hash value of -2 for -1 + y = value + if y == -1: + y = -2 elif typetuple[i] == float: # get the correct hash for float which is an # integer & other less frequent cases diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py --- a/pypy/objspace/std/test/test_specialisedtupleobject.py +++ b/pypy/objspace/std/test/test_specialisedtupleobject.py @@ -177,6 +177,10 @@ assert hash(a) == hash((1L, 2L)) == hash((1.0, 2.0)) == hash((1.0, 2L)) + x = (-1, -1) + y = tuple([-1, -1]) + assert hash(x) == hash(y) + def test_getitem(self): t = (5, 3) assert (t)[0] == 5 diff --git a/pypy/objspace/test/test_descriptor.py b/pypy/objspace/test/test_descriptor.py --- a/pypy/objspace/test/test_descriptor.py +++ b/pypy/objspace/test/test_descriptor.py @@ -149,6 +149,9 @@ pass class myfloat(float): pass + class myHashClass(object): + def __hash__(self): + return -1 assert hash(-1) == -2 assert hash(-1L) == -2 @@ -157,4 +160,4 @@ assert hash(myint(-1)) == -2 assert hash(mylong(-1)) == -2 assert hash(myfloat(-1.0)) == -2 - + assert hash(myHashClass()) == -2 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit