[pypy-svn] r5583 - in pypy/trunk/src/pypy: module objspace objspace/std objspace/std/test

mwh at codespeak.net mwh at codespeak.net
Thu Jul 15 12:32:37 CEST 2004


Author: mwh
Date: Thu Jul 15 12:32:35 2004
New Revision: 5583

Added:
   pypy/trunk/src/pypy/objspace/std/fake.py
Removed:
   pypy/trunk/src/pypy/objspace/std/cpythonobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_cpythonobject.py
Modified:
   pypy/trunk/src/pypy/module/__builtin__module.py
   pypy/trunk/src/pypy/objspace/descroperation.py
   pypy/trunk/src/pypy/objspace/std/objspace.py
   pypy/trunk/src/pypy/objspace/std/typeobject.py
Log:
This is the outcome of the 'die, cpythonobject die!' thread on
pypy-dev.

Few changes from the last posted version, most of which are in aid of 
getting faking unicode to work.

Now would be a good time to implement basestring and have str inherit 
from it, methinks.


Modified: pypy/trunk/src/pypy/module/__builtin__module.py
==============================================================================
--- pypy/trunk/src/pypy/module/__builtin__module.py	(original)
+++ pypy/trunk/src/pypy/module/__builtin__module.py	Thu Jul 15 12:32:35 2004
@@ -10,8 +10,9 @@
 __builtins__['__debug__']  = True
 
 object = __interplevel__eval('space.w_object')
-basestring = str    # XXX until we have unicode
-
+# XXX these are faked:
+basestring = __interplevel__eval('space.wrap(basestring)')
+unicode = __interplevel__eval('space.wrap(unicode)')
 
 # TODO Fix this later to show Ctrl-D on Unix
 quit = exit = "Use Ctrl-Z (i.e. EOF) to exit."

Modified: pypy/trunk/src/pypy/objspace/descroperation.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/descroperation.py	(original)
+++ pypy/trunk/src/pypy/objspace/descroperation.py	Thu Jul 15 12:32:35 2004
@@ -52,6 +52,8 @@
     def descr__init__(space, w_obj, __args__):
         pass   # XXX some strange checking maybe
 
+SlotWrapper = type(None).__repr__
+
 class DescrOperation:
 
     def getdict(space, w_obj):
@@ -62,15 +64,17 @@
 
     def get_and_call_args(space, w_descr, w_obj, args):
         descr = space.unwrap_builtin(w_descr)
+        # some special cases to avoid infinite recursion
         if type(descr) is Function:
-            # special-case Functions to avoid infinite recursion
             if isinstance(descr.code, BuiltinCode):
                 # this sub-special case is ONLY for performance reasons
-                w_result = descr.code.performance_shortcut_call_meth(space,
-                                                                     w_obj, args)
+                w_result = descr.code.performance_shortcut_call_meth(
+                    space, w_obj, args)
                 if w_result is not None:
                     return w_result
             return descr.call_args(args.prepend(w_obj))
+        elif type(descr) is type(space.wrap(SlotWrapper)):
+            return descr.call_args(args.prepend(w_obj))
         else:
             w_impl = space.get(w_descr, w_obj)
             return space.call_args(w_impl, args)

Deleted: /pypy/trunk/src/pypy/objspace/std/cpythonobject.py
==============================================================================
--- /pypy/trunk/src/pypy/objspace/std/cpythonobject.py	Thu Jul 15 12:32:35 2004
+++ (empty file)
@@ -1,380 +0,0 @@
-"""
-"""
-
-from pypy.objspace.std.objspace import *
-from pypy.interpreter.function import Function
-from pypy.objspace.std.default import UnwrapError
-import sys, operator, types
-
-class W_BuiltinFunctionObject(Function):
-    """This class wraps cpython-functions much like ordinary 'Function' objects 
-       but it avoids wrapping them into CPythonObject which would go badly 
-       with the descroperations. """ 
-
-    def __init__(self, space, cpyfunc):
-        assert callable(cpyfunc), cpyfunc
-        self.space = space
-        self.cpyfunc = cpyfunc
-
-    def call_args(self, args):
-        space = self.space
-        try:
-            unwrappedargs = [space.unwrap(w_arg) for w_arg in args.args_w]
-            unwrappedkwds = dict([(key, space.unwrap(w_value))
-                                  for key, w_value in args.kwds_w.items()])
-        except UnwrapError, e:
-            raise UnwrapError('calling %s: %s' % (self.cpyfunc, e))
-        try:
-            result = apply(self.cpyfunc, unwrappedargs, unwrappedkwds)
-        except:
-            wrap_exception(space)
-        return space.wrap(result)
-
-class W_CPythonObject(W_Object):
-    "This class wraps an arbitrary CPython object."
-    
-    def __init__(w_self, space, cpyobj):
-        W_Object.__init__(w_self, space)
-        w_self.cpyobj = cpyobj
-        w_self.w_cpytype = None
-
-    def __repr__(w_self):
-        """ representation for debugging purposes """
-        return "cpyobj(%r)" % (w_self.cpyobj,)
-
-    def getclass(w_self, space):
-        if w_self.w_cpytype is None:
-            try:
-                w_self.w_cpytype = space.wrap(w_self.cpyobj.__class__)
-            except AttributeError:   # no __class__!
-                w_self.w_cpytype = space.wrap(type(w_self.cpyobj))
-        return w_self.w_cpytype
-
-    def lookup(w_self, name):
-        # hack for wrapped CPython types
-        cls = w_self.cpyobj
-        if isinstance(cls, type):
-            for base in cls.__mro__:
-                if name in base.__dict__:
-                    return w_self.space.wrap(base.__dict__[name])
-            return None
-        elif isinstance(cls, types.ClassType):
-            while True:
-                if name in cls.__dict__:
-                    return w_self.space.wrap(base.__dict__[name])
-                if not cls.__bases__:
-                    return None
-                cls, = cls.__bases__  # no old-style multiple inheritance
-        else:
-            raise TypeError, '%r is not a class' % (cls,)
-
-registerimplementation(W_CPythonObject)
-
-
-def cpython_unwrap(space, w_obj):
-    cpyobj = w_obj.cpyobj
-    #if hasattr(type(cpyobj), '__unwrap__'):
-    #    cpyobj = cpyobj.__unwrap__()
-    return cpyobj
-
-StdObjSpace.unwrap.register(cpython_unwrap, W_CPythonObject)
-
-# XXX we hack a bit to delegate ints to longs here
-#def hacky_delegate_to_long(space, w_intobj):
-#    return space.wrap(long(w_intobj.intval))
-#hacky_delegate_to_long.result_class = W_CPythonObject  # XXX
-#hacky_delegate_to_long.priority = PRIORITY_CHANGE_TYPE + 0.1  # XXX too
-#StdObjSpace.delegate.register(hacky_delegate_to_long, W_IntObject)
-
-
-# XXX XXX XXX
-# std space lookup now *refers directly* to the cpython descriptors
-# so the multimethods implementations here are not reachable
-# nor used, except for things implemented as multimethod directly on the space
-# not through descriptors in DescrOperation
-#
-# delegate
-# id
-# issubtype
-# ord
-# round
-# unwrap
-#
-# TODO kill
-
-
-
-# real-to-wrapped exceptions
-def wrap_exception(space):
-    exc, value, tb = sys.exc_info()
-    if exc is OperationError:
-        raise exc, value, tb   # just re-raise it
-    name = exc.__name__
-    if hasattr(space, 'w_' + name):
-        w_exc = getattr(space, 'w_' + name)
-        w_value = space.call_function(w_exc,
-            *[space.wrap(a) for a in value.args])
-        for key, value in value.__dict__.items():
-            if not key.startswith('_'):
-                space.setattr(w_value, space.wrap(key), space.wrap(value))
-    else:
-        w_exc = space.wrap(exc)
-        w_value = space.wrap(value)
-    raise OperationError, OperationError(w_exc, w_value), tb
-
-# in-place operators
-def inplace_pow(x1, x2):
-    x1 **= x2
-    return x1
-def inplace_mul(x1, x2):
-    x1 *= x2
-    return x1
-def inplace_truediv(x1, x2):
-    x1 /= x2  # XXX depends on compiler flags
-    return x1
-def inplace_floordiv(x1, x2):
-    x1 //= x2
-    return x1
-def inplace_div(x1, x2):
-    x1 /= x2  # XXX depends on compiler flags
-    return x1
-def inplace_mod(x1, x2):
-    x1 %= x2
-    return x1
-
-def inplace_add(x1, x2):
-    x1 += x2
-    return x1
-def inplace_sub(x1, x2):
-    x1 -= x2
-    return x1
-def inplace_lshift(x1, x2):
-    x1 <<= x2
-    return x1
-def inplace_rshift(x1, x2):
-    x1 >>= x2
-    return x1
-def inplace_and(x1, x2):
-    x1 &= x2
-    return x1
-def inplace_or(x1, x2):
-    x1 |= x2
-    return x1
-def inplace_xor(x1, x2):
-    x1 ^= x2
-    return x1
-
-def getter(o, i, c):
-    if hasattr(o, '__get__'):
-        return o.__get__(i, c)
-    else:
-        return o
-
-# regular part of the interface (minus 'next' and 'call')
-MethodImplementation = {
-    'id':                 id,
-    'type':               type,
-#    'issubtype':          see below,
-    'repr':               repr,
-    'str':                str,
-    'len':                len,
-    'hash':               hash,
-    'getattr':            getattr,
-    'setattr':            setattr,
-    'delattr':            delattr,
-#    'getitem':            see below,
-#    'setitem':            see below,
-#    'delitem':            see below,
-    'pos':                operator.pos,
-    'neg':                operator.neg,
-    'abs':                operator.abs,
-    'hex':                hex,
-    'oct':                oct,
-    'ord':                ord,
-    'invert':             operator.invert,
-    'add':                operator.add,
-    'sub':                operator.sub,
-    'mul':                operator.mul,
-    'truediv':            operator.truediv,
-    'floordiv':           operator.floordiv,
-    'div':                operator.div,
-    'mod':                operator.mod,
-    'divmod':             divmod,
-    'pow':                pow,
-    'lshift':             operator.lshift,
-    'rshift':             operator.rshift,
-    'and_':               operator.and_,
-    'or_':                operator.or_,
-    'xor':                operator.xor,
-    'int':                int,
-    'float':              float,
-    'inplace_add':        inplace_add,
-    'inplace_sub':        inplace_sub,
-    'inplace_mul':        inplace_mul,
-    'inplace_truediv':    inplace_truediv,
-    'inplace_floordiv':   inplace_floordiv,
-    'inplace_div':        inplace_div,
-    'inplace_mod':        inplace_mod,
-    'inplace_pow':        inplace_pow,
-    'inplace_lshift':     inplace_lshift,
-    'inplace_rshift':     inplace_rshift,
-    'inplace_and':        inplace_and,
-    'inplace_or':         inplace_or,
-    'inplace_xor':        inplace_xor,
-    'lt':                 operator.lt,
-    'le':                 operator.le,
-    'eq':                 operator.eq,
-    'ne':                 operator.ne,
-    'gt':                 operator.gt,
-    'ge':                 operator.ge,
-    'contains':           operator.contains,
-    'iter':               iter,
-    'get':                getter,
-#    'set':                setter,
-#    'delete':             deleter,
-    }
-
-for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
-    f = MethodImplementation.get(_name)
-    if f:
-        if _arity == 1:
-            def cpython_f(space, w_1, f=f): 
-                x1 = w_1.cpyobj 
-                type_x1 = type(x1)
-                try:
-                    y = f(x1)
-                except:
-                    wrap_exception(space)
-                return space.wrap(y)
-        elif _arity == 2:
-            def cpython_f(space, w_1, w_2, f=f): 
-                x1 = w_1.cpyobj 
-                type_x1 = type(x1)
-                # XXX do we really want to unwrap unknown objects here? 
-                x2 = space.unwrap(w_2)
-                try:
-                    y = f(x1, x2)
-                except:
-                    wrap_exception(space)
-                return space.wrap(y)
-        elif _arity == 3:
-            def cpython_f(space, w_1, w_2, w_3, f=f): 
-                x1 = w_1.cpyobj 
-                type_x1 = type(x1)
-                x2 = space.unwrap(w_2)
-                x3 = space.unwrap(w_3)
-                try:
-                    y = f(x1, x2, x3)
-                except:
-                    wrap_exception(space)
-                return space.wrap(y)
-        else:
-            raise ValueError, '_arity too large'
-
-        arglist = [W_CPythonObject] + [W_ANY]*(_arity-1)
-        #if _name == 'getattr': _name = 'getattribute'  # XXX hack
-        multimethod = getattr(StdObjSpace.MM, _name)
-        multimethod.register(cpython_f, *arglist)
-
-        if len(multimethod.specialnames) > 1 and _arity == 2:
-            def cpython_f_rev(space, w_1, w_2, f=f):
-                # XXX do we really want to unwrap unknown objects here? 
-                x1 = space.unwrap(w_1)
-                x2 = w_2.cpyobj 
-                try:
-                    y = f(x1, x2)
-                except:
-                    wrap_exception(space)
-                return space.wrap(y)
-            multimethod.register(cpython_f_rev, W_ANY, W_CPythonObject)
-
-def nonzero__CPython(space, w_obj):
-    obj = space.unwrap(w_obj)
-    try:
-        return space.newbool(operator.truth(obj))
-    except:
-        wrap_exception(space)
-
-
-# slicing
-def old_slice(index):
-    # return the (start, stop) indices of the slice, or None
-    # if the w_index is not a slice or a slice with a step
-    # this is no longer useful in Python 2.3
-    if isinstance(index, types.SliceType):
-        if index.step is None or index.step == 1:
-            start, stop = index.start, index.stop
-            if start is None: start = 0
-            if stop  is None: stop  = sys.maxint
-            return start, stop
-    return None
-
-def getitem__CPython_ANY(space, w_obj, w_index):
-    obj = space.unwrap(w_obj)
-    index = space.unwrap(w_index)
-    sindex = old_slice(index)
-    try:
-        if sindex is None:
-            result = obj[index]
-        else:
-            result = operator.getslice(obj, sindex[0], sindex[1])
-    except:
-        wrap_exception(space)
-    return space.wrap(result)
-
-def setitem__CPython_ANY_ANY(space, w_obj, w_index, w_value):
-    obj = space.unwrap(w_obj)
-    index = space.unwrap(w_index)
-    value = space.unwrap(w_value)
-    sindex = old_slice(index)
-    try:
-        if sindex is None:
-            obj[index] = value
-        else:
-            operator.setslice(obj, sindex[0], sindex[1], value)
-    except:
-        wrap_exception(space)
-
-def delitem__CPython_ANY(space, w_obj, w_index):
-    obj = space.unwrap(w_obj)
-    index = space.unwrap(w_index)
-    sindex = old_slice(index)
-    try:
-        if sindex is None:
-            del obj[index]
-        else:
-            operator.delslice(obj, sindex[0], sindex[1])
-    except:
-        wrap_exception(space)
-
-def next__CPython(space, w_obj):
-    obj = space.unwrap(w_obj)
-    try:
-        result = obj.next()
-    except:
-        wrap_exception(space)
-    return space.wrap(result)
-
-def call__CPython(space, w_obj, w_arguments, w_keywords):
-    # XXX temporary hack similar to objspace.trivial.call()
-    callable = space.unwrap(w_obj)
-    args = space.unwrap(w_arguments)
-    keywords = space.unwrap(w_keywords)
-    try:
-        result = apply(callable, args, keywords)
-    except:
-        import sys
-        wrap_exception(space)
-    return space.wrap(result)
-
-def issubtype__CPython_ANY(space, w_obj, w_other):
-    return space.newbool(0)
-
-def issubtype__ANY_CPython(space, w_obj, w_other):
-    return space.newbool(0)
-
-def issubtype__CPython_CPython(space, w_obj, w_other):
-    return space.newbool(issubclass(space.unwrap(w_obj),
-                                    space.unwrap(w_other)))
-
-register_all(vars())

Added: pypy/trunk/src/pypy/objspace/std/fake.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/objspace/std/fake.py	Thu Jul 15 12:32:35 2004
@@ -0,0 +1,77 @@
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.std.objspace import W_Object
+from pypy.objspace.std.default import UnwrapError
+
+# this file automatically generates non-reimplementations of CPython
+# types that we do not yet implement in the standard object space
+# (files being the biggy)
+
+import sys
+
+# real-to-wrapped exceptions
+def wrap_exception(space):
+    exc, value, tb = sys.exc_info()
+    if exc is OperationError:
+        raise exc, value, tb   # just re-raise it
+    name = exc.__name__
+    if hasattr(space, 'w_' + name):
+        w_exc = getattr(space, 'w_' + name)
+        w_value = space.call_function(w_exc,
+            *[space.wrap(a) for a in value.args])
+        for key, value in value.__dict__.items():
+            if not key.startswith('_'):
+                space.setattr(w_value, space.wrap(key), space.wrap(value))
+    else:
+        w_exc = space.wrap(exc)
+        w_value = space.wrap(value)
+    raise OperationError, OperationError(w_exc, w_value), tb
+
+def fake_type(space, cpy_type):
+    assert type(cpy_type) is type
+    kw = {}
+    for s, v in cpy_type.__dict__.items():
+        kw[s] = v
+    def fake__new__(space, w_type, *args_w):
+        args = [space.unwrap(w_arg) for w_arg in args_w]
+        try:
+            r = cpy_type.__new__(cpy_type, *args)
+        except:
+            wrap_exception(space)
+        return W_Fake(space, r)
+    def fake_unwrap(space, w_obj):
+        return w_obj.val
+    kw['__new__'] = gateway.interp2app(fake__new__)
+    if cpy_type.__base__ is not object:
+        base = space.wrap(cpy_type.__base__).instancetypedef
+    else:
+        base = None
+    class W_Fake(W_Object):
+        typedef = StdTypeDef(
+            cpy_type.__name__, base, **kw)
+        def __init__(w_self, space, val):
+            W_Object.__init__(w_self, space)
+            w_self.val = val
+    space.__class__.unwrap.register(fake_unwrap, W_Fake)
+    W_Fake.__name__ = 'W_Fake(%s)'%(cpy_type.__name__)
+    W_Fake.typedef.fakedcpytype = cpy_type
+    # XXX obviously this entire file is something of a hack, but it
+    # manages to get worse here:
+    if cpy_type is type(type(None).__repr__):
+        def call_args(self, args):
+            try:
+                unwrappedargs = [space.unwrap(w_arg) for w_arg in args.args_w]
+                unwrappedkwds = dict([(key, space.unwrap(w_value))
+                                      for key, w_value in args.kwds_w.items()])
+            except UnwrapError, e:
+                raise UnwrapError('calling %s: %s' % (cpy_type, e))
+            try:
+                assert callable(self.val), self.val
+                result = apply(self.val, unwrappedargs, unwrappedkwds)
+            except:
+                wrap_exception(space)
+            return space.wrap(result)
+
+        setattr(W_Fake, "call_args", call_args)
+    return W_Fake
+        

Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py	Thu Jul 15 12:32:35 2004
@@ -134,6 +134,8 @@
         return done
                             
     def initialize(self):
+        self.fake_type_cache = {}
+        
         # The object implementations that we want to 'link' into PyPy must be
         # imported here.  This registers them into the multimethod tables,
         # *before* the type objects are built from these multimethod tables.
@@ -150,13 +152,12 @@
         from pypy.objspace.std import longobject
         from pypy.objspace.std import noneobject
         from pypy.objspace.std import iterobject
-        from pypy.objspace.std import cpythonobject
         # hack to avoid imports in the time-critical functions below
         global W_ObjectObject, W_BoolObject, W_IntObject, W_FloatObject
         global W_TupleObject, W_ListObject, W_DictObject, W_StringObject
         global W_TypeObject, W_SliceObject, W_LongObject, W_NoneObject
         global W_SeqIterObject
-        global W_CPythonObject, W_BuiltinFunctionObject
+        global W_FakeFile
         W_ObjectObject = objectobject.W_ObjectObject
         W_BoolObject = boolobject.W_BoolObject
         W_IntObject = intobject.W_IntObject
@@ -170,10 +171,7 @@
         W_LongObject = longobject.W_LongObject
         W_NoneObject = noneobject.W_NoneObject
         W_SeqIterObject = iterobject.W_SeqIterObject
-        W_CPythonObject = cpythonobject.W_CPythonObject
-        W_BuiltinFunctionObject = cpythonobject.W_BuiltinFunctionObject
         # end of hacks
-
         # singletons
         self.w_None  = W_NoneObject(self)
         self.w_False = W_BoolObject(self, False)
@@ -197,6 +195,14 @@
             setattr(self, 'w_' + typedef.name, w_type)
             for_builtins[typedef.name] = w_type
 
+        import fake
+        W_FakeFile = fake.fake_type(self, file)
+
+        self.w_file = self.gettypeobject(W_FakeFile.typedef)
+        for_builtins['file'] = self.w_file
+        self.fake_type_cache[file] = W_FakeFile
+        
+        
         # exceptions
         for_builtins.update(self.clone_exception_hierarchy())
         
@@ -240,17 +246,26 @@
             #print 'wrapping', x, '->', w_result
             return w_result
         # anything below this line is implicitly XXX'ed
-        SlotWrapperType = type(type(None).__repr__)
-        if isinstance(x, (types.FunctionType, types.BuiltinFunctionType, SlotWrapperType)):
-            return W_BuiltinFunctionObject(self, x)
         if isinstance(x, type(Exception)) and issubclass(x, Exception):
             if hasattr(self, 'w_' + x.__name__):
                 return getattr(self, 'w_' + x.__name__)
-        print "cpython wrapping %r" % (x,)
-        #if hasattr(x, '__bases__'): 
-        #    print "cpython wrapping a class %r (%s)" % (x, type(x))
-            #raise TypeError, "cannot wrap classes"
-        return W_CPythonObject(self, x)
+        if isinstance(x, type):
+            if x in self.fake_type_cache:
+                return self.gettypeobject(self.fake_type_cache[x].typedef)
+            print 'faking %r'%(x,)
+            import fake
+            ft = fake.fake_type(self, x)
+            self.fake_type_cache[x] = ft
+            return self.gettypeobject(self.fake_type_cache[x].typedef)
+        if type(x) in self.fake_type_cache:
+            ft = self.fake_type_cache[type(x)]
+            return ft(self, x)
+        else:
+            print 'faking %r'%(type(x),)
+            import fake
+            ft = fake.fake_type(self, type(x))
+            self.fake_type_cache[type(x)] = ft
+            return ft(self, x)
 
     def newint(self, intval):
         return W_IntObject(self, intval)
@@ -335,14 +350,8 @@
 
     def is_(self, w_one, w_two):
         # XXX a bit of hacking to gain more speed 
-        #
         if w_one is w_two:
             return self.w_True
-        if isinstance(w_one, W_CPythonObject):
-            if isinstance(w_two, W_CPythonObject):
-                if w_one.cpyobj is w_two.cpyobj:
-                    return self.w_True
-                return self.newbool(self.unwrap(w_one) is self.unwrap(w_two))
         return self.w_False
 
     def is_true(self, w_obj):
@@ -353,26 +362,19 @@
             return DescrOperation.is_true(self, w_obj)
 
     def hash(space, w_obj):
-        if isinstance(w_obj, W_CPythonObject):
-            try:
-                return space.newint(hash(w_obj.cpyobj))
-            except:
-                from pypy.objspace.std import cpythonobject
-                cpythonobject.wrap_exception(space)
-        else:
-            w = space.wrap
-            eq = '__eq__'
-            ne = '__ne__'
-            hash_s = '__hash__'
-
-            for w_t in space.type(w_obj).mro_w:
-                d = w_t.dict_w
-                if hash_s in d:
-                    w_descr = d[hash_s]
-                    return space.get_and_call_function(w_descr, w_obj)
-                if eq in d:                
-                    raise OperationError(space.w_TypeError, w("unhashable type"))
-            return space.id(w_obj)
+        w = space.wrap
+        eq = '__eq__'
+        ne = '__ne__'
+        hash_s = '__hash__'
+
+        for w_t in space.type(w_obj).mro_w:
+            d = w_t.dict_w
+            if hash_s in d:
+                w_descr = d[hash_s]
+                return space.get_and_call_function(w_descr, w_obj)
+            if eq in d:                
+                raise OperationError(space.w_TypeError, w("unhashable type"))
+        return space.id(w_obj)
         
 # add all regular multimethods to StdObjSpace
 for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:

Deleted: /pypy/trunk/src/pypy/objspace/std/test/test_cpythonobject.py
==============================================================================
--- /pypy/trunk/src/pypy/objspace/std/test/test_cpythonobject.py	Thu Jul 15 12:32:35 2004
+++ (empty file)
@@ -1,90 +0,0 @@
-import unittest, sys, array
-import autopath
-from pypy.tool import testit
-from pypy.objspace.std import cpythonobject
-from pypy.objspace.std.objspace import OperationError
-
-
-class TestW_CPythonObject(testit.TestCase):
-
-    def setUp(self):
-        self.space = testit.objspace('std')
-        # arbitrary always-wrapped object
-        self.stuff = array.array('b', [5,-2,77])
-
-    def tearDown(self):
-        pass
-
-    def test_unary(self):
-        w1 = self.space.wrap(self.stuff)
-        for op, expected in [
-            ('id',     id(self.stuff)),
-            ('type',   array.ArrayType),
-            ('len',    3),
-            ('repr',   "array('b', [5, -2, 77])"),
-            ('str',    "array('b', [5, -2, 77])"),
-            ]:
-            w_result = getattr(self.space, op)(w1)
-            self.assertEquals(self.space.unwrap(w_result), expected)
-
-    def test_binary(self):
-        w1 = self.space.wrap(self.stuff)
-        for op, w_arg, expected in [
-#            ('getattr',   self.space.wrap('count'),      self.stuff.count),
-            ('getitem',   self.space.wrap(1),            -2),
-            ('getitem',   self.space.wrap(slice(1,2)),   array.array('b', [-2])),
-            ]:
-            w_result = getattr(self.space, op)(w1, w_arg)
-            self.assertEquals(self.space.unwrap(w_result), expected)
-
-    def test_unaryop(self):
-        w1 = self.space.wrap(3+4j)
-        for op, expected in [
-            ('pos',       3+4j),
-            ('neg',      -3-4j),
-            ('not_',     False),
-            ('abs',      5.0),
-            ('hash',     hash(3+4j)),
-            ]:
-            w_result = getattr(self.space, op)(w1)
-            self.assertEquals(self.space.unwrap(w_result), expected)
-
-    def test_binaryop(self):
-        w1 = self.space.wrap(3+4j)
-        w2 = self.space.wrap(1-2j)
-        for op, expected in [
-            ('add',      (3+4j) + (1-2j)),
-            ('sub',      (3+4j) - (1-2j)),
-            ('mul',      (3+4j) * (1-2j)),
-            ('div',      (3+4j) / (1-2j)),
-            ('eq',       False),
-            ('ne',       True),
-            ]:
-            w_result = getattr(self.space, op)(w1, w2)
-            self.assertEquals(self.space.unwrap(w_result), expected)
-
-    def test_unhashable(self):
-        w1 = self.space.wrap(self.stuff)
-        self.assertRaises(OperationError, self.space.hash, w1)
-        try: self.space.hash(w1)
-        except OperationError, e:
-            self.assertEquals(e.w_type, self.space.w_TypeError)
-
-    def test_hashable(self):
-        uw = 3+4j
-        w1 = self.space.wrap(uw)
-        hash_result = self.space.hash(w1)
-        self.assertEquals(self.space.unwrap(hash_result), hash(uw))
-        
-    def test_call(self):
-        w1 = self.space.wrap(len)
-        w_result = self.space.call_function(w1, self.space.wrap("hello world"))
-        self.assertEquals(self.space.unwrap(w_result), 11)
-
-    def test_next(self):
-        # create something with a next
-        nx = self.space.wrap(iter(self.stuff))
-        self.assertEqual_w(self.space.wrap(5), self.space.next(nx))
-
-if __name__ == '__main__':
-    testit.main()

Modified: pypy/trunk/src/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/typeobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/typeobject.py	Thu Jul 15 12:32:35 2004
@@ -137,6 +137,11 @@
 # XXX __delattr__
 # XXX __hash__ ??
 
+def unwrap__Type(space, w_type):
+    if hasattr(w_type.instancetypedef, 'fakedcpytype'):
+        return w_type.instancetypedef.fakedcpytype
+    raise FailedToImplement
+
 # ____________________________________________________________
 
 def compute_C3_mro(cls):



More information about the Pypy-commit mailing list