[pypy-svn] r54078 - in pypy/branch/2.5-features/pypy: module/__builtin__ module/__builtin__/test objspace

bgola at codespeak.net bgola at codespeak.net
Thu Apr 24 07:32:20 CEST 2008


Author: bgola
Date: Thu Apr 24 07:32:18 2008
New Revision: 54078

Modified:
   pypy/branch/2.5-features/pypy/module/__builtin__/interp_classobj.py
   pypy/branch/2.5-features/pypy/module/__builtin__/test/test_classobj.py
   pypy/branch/2.5-features/pypy/objspace/descroperation.py
Log:
2.5 __hash__ new behavior, can return either a long or an integer

Modified: pypy/branch/2.5-features/pypy/module/__builtin__/interp_classobj.py
==============================================================================
--- pypy/branch/2.5-features/pypy/module/__builtin__/interp_classobj.py	(original)
+++ pypy/branch/2.5-features/pypy/module/__builtin__/interp_classobj.py	Thu Apr 24 07:32:18 2008
@@ -541,10 +541,11 @@
             else:
                 return space.wrap(hash(self))
         w_ret = space.call_function(w_func)
-        if not space.is_true(space.isinstance(w_ret, space.w_int)):
+        if (not space.is_true(space.isinstance(w_ret, space.w_int)) and
+            not space.is_true(space.isinstance(w_ret, space.w_long))):
             raise OperationError(
                 space.w_TypeError,
-                space.wrap("__hash__ must return int"))
+                space.wrap("__hash__ must return int or long"))
         return w_ret
 
     def descr_index(self, space):

Modified: pypy/branch/2.5-features/pypy/module/__builtin__/test/test_classobj.py
==============================================================================
--- pypy/branch/2.5-features/pypy/module/__builtin__/test/test_classobj.py	(original)
+++ pypy/branch/2.5-features/pypy/module/__builtin__/test/test_classobj.py	Thu Apr 24 07:32:18 2008
@@ -484,6 +484,11 @@
                 return 1
         a = A()
         raises(TypeError, hash, a)
+        class A: # can return long 
+            def __hash__(self):
+                return long(1)
+        a = A()
+        assert hash(a) == long(1)
 
     def test_index(self):
         import sys

Modified: pypy/branch/2.5-features/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/2.5-features/pypy/objspace/descroperation.py	Thu Apr 24 07:32:18 2008
@@ -287,11 +287,12 @@
                                      space.wrap("unhashable type"))
             return default_identity_hash(space, w_obj)
         w_result = space.get_and_call_function(w_hash, w_obj)
-        if space.is_true(space.isinstance(w_result, space.w_int)): 
+        if (space.is_true(space.isinstance(w_result, space.w_int)) or
+            space.is_true(space.isinstance(w_result, space.w_long))): 
             return w_result 
         else: 
             raise OperationError(space.w_TypeError, 
-                     space.wrap("__hash__() should return an int"))
+                     space.wrap("__hash__() should return an int or long"))
 
     def userdel(space, w_obj):
         w_del = space.lookup(w_obj, '__del__')



More information about the Pypy-commit mailing list