[pypy-svn] r77538 - in pypy/branch/fast-forward/pypy: interpreter interpreter/test objspace objspace/std

afa at codespeak.net afa at codespeak.net
Fri Oct 1 18:26:13 CEST 2010


Author: afa
Date: Fri Oct  1 18:26:11 2010
New Revision: 77538

Modified:
   pypy/branch/fast-forward/pypy/interpreter/test/test_typedef.py
   pypy/branch/fast-forward/pypy/interpreter/typedef.py
   pypy/branch/fast-forward/pypy/objspace/descroperation.py
   pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py
   pypy/branch/fast-forward/pypy/objspace/std/dicttype.py
   pypy/branch/fast-forward/pypy/objspace/std/listtype.py
   pypy/branch/fast-forward/pypy/objspace/std/objecttype.py
   pypy/branch/fast-forward/pypy/objspace/std/settype.py
   pypy/branch/fast-forward/pypy/objspace/std/slicetype.py
   pypy/branch/fast-forward/pypy/objspace/std/stdtypedef.py
Log:
Set list.__hash__ is now None, instead of a function that raises TypeError.
no_hash_descr() is gone!

This fixes
    isinstance([], _abcoll.Hashable)


Modified: pypy/branch/fast-forward/pypy/interpreter/test/test_typedef.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/test/test_typedef.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/test/test_typedef.py	Fri Oct  1 18:26:11 2010
@@ -145,6 +145,19 @@
         w_obj = self.space.wrap(W_SomeType())
         assert self.space.getattr(w_obj, self.space.wrap('x')) is self.space.w_None
 
+    def test_unhashable(self):
+        class W_SomeType(Wrappable):
+            pass
+        W_SomeType.typedef = typedef.TypeDef(
+            'some_type',
+            __hash__ = None)
+        w_obj = self.space.wrap(W_SomeType())
+        self.space.appexec([w_obj], """(obj):
+            assert type(obj).__hash__ is None
+            err = raises(TypeError, hash, obj)
+            assert err.value.message == "'some_type' objects are unhashable"
+            """)
+
 
 class AppTestTypeDef:
 

Modified: pypy/branch/fast-forward/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/typedef.py	Fri Oct  1 18:26:11 2010
@@ -51,13 +51,6 @@
 def default_identity_hash(space, w_obj):
     return space.wrap(compute_identity_hash(w_obj))
 
-def descr__hash__unhashable(space, w_obj):
-    typename = space.type(w_obj).getname(space, '?')
-    raise operationerrfmt(space.w_TypeError,
-                          "'%s' objects are unhashable", typename)
-
-no_hash_descr = interp2app(descr__hash__unhashable)
-
 # ____________________________________________________________
 #
 # For each built-in app-level type Xxx that can be subclassed at
@@ -885,7 +878,7 @@
     __eq__       = interp2app(Cell.descr__eq__,
                               unwrap_spec=['self', ObjSpace, W_Root]),
     __ne__       = descr_generic_ne,
-    __hash__     = no_hash_descr,
+    __hash__     = None,
     __reduce__   = interp2app(Cell.descr__reduce__,
                               unwrap_spec=['self', ObjSpace]),
     __setstate__ = interp2app(Cell.descr__setstate__,

Modified: pypy/branch/fast-forward/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/descroperation.py	Fri Oct  1 18:26:11 2010
@@ -392,6 +392,10 @@
             # default __hash__.  This path should only be taken under very
             # obscure circumstances.
             return default_identity_hash(space, w_obj)
+        if space.is_w(w_hash, space.w_None):
+            typename = space.type(w_obj).getname(space, '?')
+            raise operationerrfmt(space.w_TypeError,
+                                  "'%s' objects are unhashable", typename)
         # XXX CPython has a special case for types with "__hash__ = None"
         # to produce a nicer error message, namely "unhashable type: 'X'".
         w_result = space.get_and_call_function(w_hash, w_obj)

Modified: pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py	Fri Oct  1 18:26:11 2010
@@ -2,7 +2,7 @@
 from pypy.interpreter import gateway
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
 from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.stdtypedef import StdTypeDef, SMM, no_hash_descr
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 
 from pypy.objspace.std.stringtype import (
     str_count, str_index, str_rindex, str_find, str_rfind, str_replace,
@@ -31,6 +31,6 @@
 
 If the argument is a bytearray, the return value is the same object.''',
     __new__ = gateway.interp2app(descr__new__),
-    __hash__ = no_hash_descr,
+    __hash__ = None,
     )
 bytearray_typedef.registermethods(globals())

Modified: pypy/branch/fast-forward/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/dicttype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/dicttype.py	Fri Oct  1 18:26:11 2010
@@ -2,7 +2,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.interpreter import gateway
-from pypy.objspace.std.stdtypedef import StdTypeDef, SMM, no_hash_descr
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 from pypy.objspace.std.register_all import register_all
 
 dict_copy       = SMM('copy',          1,
@@ -179,7 +179,7 @@
                                  unwrap_spec=
                                  [gateway.ObjSpace,
                                   gateway.W_Root,gateway.Arguments]),
-    __hash__ = no_hash_descr,
+    __hash__ = None,
     fromkeys = gateway.interp2app(descr_fromkeys, as_classmethod=True),
     )
 dict_typedef.registermethods(globals())

Modified: pypy/branch/fast-forward/pypy/objspace/std/listtype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/listtype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/listtype.py	Fri Oct  1 18:26:11 2010
@@ -1,6 +1,6 @@
 from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
-from pypy.objspace.std.stdtypedef import StdTypeDef, SMM, no_hash_descr
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 from pypy.objspace.std.register_all import register_all
 from sys import maxint
 
@@ -54,7 +54,7 @@
     __new__ = gateway.interp2app(descr__new__, unwrap_spec=[gateway.ObjSpace,
                                                gateway.W_Root,
                                                gateway.Arguments]),
-    __hash__ = no_hash_descr,
+    __hash__ = None,
     )
 list_typedef.registermethods(globals())
 

Modified: pypy/branch/fast-forward/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/objecttype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/objecttype.py	Fri Oct  1 18:26:11 2010
@@ -4,7 +4,7 @@
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.baseobjspace import ObjSpace
 from pypy.objspace.descroperation import Object
-from pypy.objspace.std.stdtypedef import StdTypeDef, no_hash_descr
+from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.register_all import register_all
 
 

Modified: pypy/branch/fast-forward/pypy/objspace/std/settype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/settype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/settype.py	Fri Oct  1 18:26:11 2010
@@ -1,7 +1,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter import gateway
 from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.stdtypedef import StdTypeDef, no_hash_descr, SMM
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 
 set_add                         = SMM('add', 2,
                                       doc='Add an element to a set.\n\nThis'
@@ -78,7 +78,7 @@
     __new__ = gateway.interp2app(descr__new__, unwrap_spec=[gateway.ObjSpace,
                                                             gateway.W_Root,
                                                             gateway.Arguments]),
-    __hash__ = no_hash_descr,
+    __hash__ = None,
     )
 
 set_typedef.registermethods(globals())

Modified: pypy/branch/fast-forward/pypy/objspace/std/slicetype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/slicetype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/slicetype.py	Fri Oct  1 18:26:11 2010
@@ -1,6 +1,6 @@
 from pypy.interpreter import baseobjspace, gateway
 from pypy.interpreter.typedef import GetSetProperty
-from pypy.objspace.std.stdtypedef import StdTypeDef, SMM, no_hash_descr
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 from pypy.objspace.std.register_all import register_all
 from pypy.interpreter.error import OperationError
 
@@ -89,7 +89,7 @@
 
 Create a slice object.  This is used for extended slicing (e.g. a[0:10:2]).''',
     __new__ = gateway.interp2app(descr__new__),
-    __hash__ = no_hash_descr,
+    __hash__ = None,
     start = slicewprop('w_start'),
     stop  = slicewprop('w_stop'),
     step  = slicewprop('w_step'),

Modified: pypy/branch/fast-forward/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/stdtypedef.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/stdtypedef.py	Fri Oct  1 18:26:11 2010
@@ -2,7 +2,7 @@
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, Member
 from pypy.interpreter.typedef import descr_get_dict, descr_set_dict
-from pypy.interpreter.typedef import no_hash_descr, descr_del_dict
+from pypy.interpreter.typedef import descr_del_dict
 from pypy.interpreter.baseobjspace import SpaceCache
 from pypy.objspace.std import model
 from pypy.objspace.std.model import StdObjSpaceMultiMethod
@@ -10,7 +10,7 @@
 from pypy.rlib import jit
 from pypy.tool.sourcetools import compile2
 
-__all__ = ['StdTypeDef', 'SMM', 'no_hash_descr']
+__all__ = ['StdTypeDef', 'SMM']
 
 SMM = StdObjSpaceMultiMethod
 



More information about the Pypy-commit mailing list