Author: p_ziesch...@yahoo.de
Branch: ep2016sprint
Changeset: r85828:c6b215318bc9
Date: 2016-07-23 16:36 +0200
http://bitbucket.org/pypy/pypy/changeset/c6b215318bc9/

Log:    Issue #2346 : Hashing of -1 did not return -2 as cpython

diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -433,8 +433,9 @@
             return w_result
         elif space.is_w(w_resulttype, space.w_long):
             # bug 2346 (return -2 for a hashvalue of -1)
-            if space.bigint_w(w_result) == -1:
-                return space.hash(space.wrap(-2))
+            w_h = space.hash(w_result)
+            if space.int_w(w_h) == -1:
+                return space.wrap(-2)
             return space.hash(w_result)
         elif space.isinstance_w(w_result, space.w_int):
             # be careful about subclasses of 'int'...
@@ -448,9 +449,10 @@
             # be careful about subclasses of 'long'...
             bigint = space.bigint_w(w_result)
             # bug 2346 (return -2 for a hashvalue of -1)
-            if bigint == -1:
-                bigint = -2
-            return space.wrap(bigint.hash())
+            h = bigint.hash()
+            if h == -1:
+                h = -2
+            return space.wrap(h)
         else:
             raise oefmt(space.w_TypeError,
                         "__hash__() should return an int or long")
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
@@ -152,6 +152,12 @@
         class myHashClass(object):
             def __hash__(self):
                 return -1
+        class myHashClass2(object):
+            def __hash__(self):
+                return -1L
+        class myHashClass3(object):
+            def __hash__(self):
+                return -10**100
 
         assert hash(-1) == -2
         assert hash(-1L) == -2
@@ -161,3 +167,5 @@
         assert hash(mylong(-1)) == -2
         assert hash(myfloat(-1.0)) == -2
         assert hash(myHashClass()) == -2
+        assert hash(myHashClass2()) == -2
+        assert hash(myHashClass3()) == hash(-10**100)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to