[pypy-commit] pypy remove-list-smm: Kill interpclass_w everywhere.

arigo noreply at buildbot.pypy.org
Wed Mar 20 22:53:58 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: remove-list-smm
Changeset: r62582:d944ad6fa63d
Date: 2013-03-20 14:53 -0700
http://bitbucket.org/pypy/pypy/changeset/d944ad6fa63d/

Log:	Kill interpclass_w everywhere.

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -216,16 +216,15 @@
         raise OperationError(space.w_TypeError,
                              typed_unwrap_error_msg(space, "integer", self))
 
-
-class Wrappable(W_Root):
-    """A subclass of Wrappable is an internal, interpreter-level class
-    that can nevertheless be exposed at application-level by space.wrap()."""
-    __slots__ = ()
-    _settled_ = True
-
     def __spacebind__(self, space):
         return self
 
+
+# ---------- backward compatibility: these classes are the same now ----------
+Wrappable = W_Root
+# ----------------------------------------------------------------------------
+
+
 class W_InterpIterable(W_Root):
     def __init__(self, space, w_iterable):
         self.w_iter = space.iter(w_iterable)
@@ -337,9 +336,8 @@
                     continue
                 raise
             modname = self.str_w(w_modname)
-            mod = self.interpclass_w(w_mod)
-            if isinstance(mod, Module) and not mod.startup_called:
-                mod.init(self)
+            if isinstance(w_mod, Module) and not w_mod.startup_called:
+                w_mod.init(self)
 
     def finish(self):
         self.wait_for_thread_shutdown()
@@ -348,9 +346,8 @@
             self.call_function(w_exitfunc)
         from pypy.interpreter.module import Module
         for w_mod in self.builtin_modules.values():
-            mod = self.interpclass_w(w_mod)
-            if isinstance(mod, Module) and mod.startup_called:
-                mod.shutdown(self)
+            if isinstance(w_mod, Module) and w_mod.startup_called:
+                w_mod.shutdown(self)
 
     def wait_for_thread_shutdown(self):
         """Wait until threading._shutdown() completes, provided the threading
@@ -422,9 +419,8 @@
 
             # And initialize it
             from pypy.interpreter.module import Module
-            mod = self.interpclass_w(w_mod)
-            if isinstance(mod, Module):
-                mod.init(self)
+            if isinstance(w_mod, Module):
+                w_mod.init(self)
             return w_mod
 
     def get_builtinmodule_to_install(self):
@@ -721,21 +717,10 @@
         w_s = self.interned_strings[s] = self.wrap(s)
         return w_s
 
-    def interpclass_w(self, w_obj):
-        """
-         If w_obj is a wrapped internal interpreter class instance unwrap to it,
-         otherwise return None.  (Can be overridden in specific spaces; you
-     should generally use the helper space.interp_w() instead.)
-        """
-        if isinstance(w_obj, Wrappable):
-            return w_obj
-        return None
-
     def descr_self_interp_w(self, RequiredClass, w_obj):
-        obj = self.interpclass_w(w_obj)
-        if not isinstance(obj, RequiredClass):
+        if not isinstance(w_obj, RequiredClass):
             raise DescrMismatch()
-        return obj
+        return w_obj
     descr_self_interp_w._annspecialcase_ = 'specialize:arg(1)'
 
     def interp_w(self, RequiredClass, w_obj, can_be_None=False):
@@ -746,13 +731,12 @@
         assert RequiredClass is not None
         if can_be_None and self.is_none(w_obj):
             return None
-        obj = self.interpclass_w(w_obj)
-        if not isinstance(obj, RequiredClass):   # or obj is None
+        if not isinstance(w_obj, RequiredClass):   # or obj is None
             msg = "'%s' object expected, got '%s' instead"
             raise operationerrfmt(self.w_TypeError, msg,
                 wrappable_class_name(RequiredClass),
                 w_obj.getclass(self).getname(self))
-        return obj
+        return w_obj
     interp_w._annspecialcase_ = 'specialize:arg(1)'
 
     def unpackiterable(self, w_iterable, expected_length=-1):
@@ -1030,8 +1014,7 @@
     def is_oldstyle_instance(self, w_obj):
         # xxx hack hack hack
         from pypy.module.__builtin__.interp_classobj import W_InstanceObject
-        obj = self.interpclass_w(w_obj)
-        return obj is not None and isinstance(obj, W_InstanceObject)
+        return isinstance(w_obj, W_InstanceObject)
 
     def callable(self, w_obj):
         if self.lookup(w_obj, "__call__") is not None:
@@ -1668,7 +1651,6 @@
 #                       float_w(w_floatval) -> floatval
 #             uint_w(w_ival or w_long_ival) -> r_uint_val (unsigned int value)
 #             bigint_w(w_ival or w_long_ival) -> rbigint
-#interpclass_w(w_interpclass_inst or w_obj) -> interpclass_inst|w_obj
 #                               unwrap(w_x) -> x
 #                              is_true(w_x) -> True or False
 #                  newtuple([w_1, w_2,...]) -> w_tuple
@@ -1685,7 +1667,6 @@
     'uint_w',
     'bigint_w',
     'unicode_w',
-    'interpclass_w',
     'unwrap',
     'is_true',
     'is_w',
diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py
--- a/pypy/interpreter/buffer.py
+++ b/pypy/interpreter/buffer.py
@@ -93,12 +93,11 @@
 
     def _make_descr__cmp(name):
         def descr__cmp(self, space, w_other):
-            other = space.interpclass_w(w_other)
-            if not isinstance(other, Buffer):
+            if not isinstance(w_other, Buffer):
                 return space.w_NotImplemented
             # xxx not the most efficient implementation
             str1 = self.as_str()
-            str2 = other.as_str()
+            str2 = w_other.as_str()
             return space.wrap(getattr(operator, name)(str1, str2))
         descr__cmp.func_name = name
         return descr__cmp
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -550,18 +550,17 @@
 
     def descr_method_eq(self, w_other):
         space = self.space
-        other = space.interpclass_w(w_other)
-        if not isinstance(other, Method):
+        if not isinstance(w_other, Method):
             return space.w_NotImplemented
         if self.w_instance is None:
-            if other.w_instance is not None:
+            if w_other.w_instance is not None:
                 return space.w_False
         else:
-            if other.w_instance is None:
+            if w_other.w_instance is None:
                 return space.w_False
-            if not space.eq_w(self.w_instance, other.w_instance):
+            if not space.eq_w(self.w_instance, w_other.w_instance):
                 return space.w_False
-        return space.eq(self.w_function, other.w_function)
+        return space.eq(self.w_function, w_other.w_function)
 
     def descr_method_hash(self):
         space = self.space
@@ -578,13 +577,14 @@
         new_inst = mod.get('method_new')
         w        = space.wrap
         w_instance = self.w_instance or space.w_None
-        function = space.interpclass_w(self.w_function)
-        if isinstance(function, Function) and isinstance(function.code, BuiltinCode):
+        w_function = self.w_function
+        if (isinstance(w_function, Function) and
+                isinstance(w_function.code, BuiltinCode)):
             new_inst = mod.get('builtin_method_new')
             if space.is_w(w_instance, space.w_None):
-                tup = [self.w_class, space.wrap(function.name)]
+                tup = [self.w_class, space.wrap(w_function.name)]
             else:
-                tup = [w_instance, space.wrap(function.name)]
+                tup = [w_instance, space.wrap(w_function.name)]
         elif space.is_w( self.w_class, space.w_None ):
             tup = [self.w_function, w_instance]
         else:
diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py
--- a/pypy/interpreter/mixedmodule.py
+++ b/pypy/interpreter/mixedmodule.py
@@ -91,13 +91,13 @@
             return None
         else:
             w_value = loader(space)
-            func = space.interpclass_w(w_value)
             # the idea of the following code is that all functions that are
             # directly in a mixed-module are "builtin", e.g. they get a
             # special type without a __get__
             # note that this is not just all functions that contain a
             # builtin code object, as e.g. methods of builtin types have to
             # be normal Functions to get the correct binding behaviour
+            func = w_value
             if (isinstance(func, Function) and
                 type(func) is not BuiltinFunction):
                 try:
diff --git a/pypy/interpreter/nestedscope.py b/pypy/interpreter/nestedscope.py
--- a/pypy/interpreter/nestedscope.py
+++ b/pypy/interpreter/nestedscope.py
@@ -34,18 +34,17 @@
         self.w_value = None
 
     def descr__cmp__(self, space, w_other):
-        other = space.interpclass_w(w_other)
-        if not isinstance(other, Cell):
+        if not isinstance(w_other, Cell):
             return space.w_NotImplemented
 
         if self.w_value is None:
-            if other.w_value is None:
+            if w_other.w_value is None:
                 return space.newint(0)
             return space.newint(-1)
-        elif other.w_value is None:
+        elif w_other.w_value is None:
             return space.newint(1)
 
-        return space.cmp(self.w_value, other.w_value)
+        return space.cmp(self.w_value, w_other.w_value)
 
     def descr__reduce__(self, space):
         w_mod = space.getbuiltinmodule('_pickle_support')
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -290,29 +290,28 @@
 
     def descr_code__eq__(self, w_other):
         space = self.space
-        other = space.interpclass_w(w_other)
-        if not isinstance(other, PyCode):
+        if not isinstance(w_other, PyCode):
             return space.w_False
-        areEqual = (self.co_name == other.co_name and
-                    self.co_argcount == other.co_argcount and
-                    self.co_nlocals == other.co_nlocals and
-                    self.co_flags == other.co_flags and
-                    self.co_firstlineno == other.co_firstlineno and
-                    self.co_code == other.co_code and
-                    len(self.co_consts_w) == len(other.co_consts_w) and
-                    len(self.co_names_w) == len(other.co_names_w) and
-                    self.co_varnames == other.co_varnames and
-                    self.co_freevars == other.co_freevars and
-                    self.co_cellvars == other.co_cellvars)
+        areEqual = (self.co_name == w_other.co_name and
+                    self.co_argcount == w_other.co_argcount and
+                    self.co_nlocals == w_other.co_nlocals and
+                    self.co_flags == w_other.co_flags and
+                    self.co_firstlineno == w_other.co_firstlineno and
+                    self.co_code == w_other.co_code and
+                    len(self.co_consts_w) == len(w_other.co_consts_w) and
+                    len(self.co_names_w) == len(w_other.co_names_w) and
+                    self.co_varnames == w_other.co_varnames and
+                    self.co_freevars == w_other.co_freevars and
+                    self.co_cellvars == w_other.co_cellvars)
         if not areEqual:
             return space.w_False
 
         for i in range(len(self.co_names_w)):
-            if not space.eq_w(self.co_names_w[i], other.co_names_w[i]):
+            if not space.eq_w(self.co_names_w[i], w_other.co_names_w[i]):
                 return space.w_False
 
         for i in range(len(self.co_consts_w)):
-            if not space.eq_w(self.co_consts_w[i], other.co_consts_w[i]):
+            if not space.eq_w(self.co_consts_w[i], w_other.co_consts_w[i]):
                 return space.w_False
 
         return space.w_True
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -607,16 +607,15 @@
         if self.space.is_w(w_top, self.space.w_None):
             # case of a finally: block with no exception
             return None
-        unroller = self.space.interpclass_w(w_top)
-        if isinstance(unroller, SuspendedUnroller):
+        if isinstance(w_top, SuspendedUnroller):
             # case of a finally: block with a suspended unroller
-            return unroller
+            return w_top
         else:
             # case of an except: block.  We popped the exception type
             self.popvalue()        #     Now we pop the exception value
-            unroller = self.space.interpclass_w(self.popvalue())
-            assert unroller is not None
-            return unroller
+            w_unroller = self.popvalue()
+            assert w_unroller is not None
+            return w_unroller
 
     def BUILD_CLASS(self, oparg, next_instr):
         w_methodsdict = self.popvalue()
@@ -944,11 +943,9 @@
         w_unroller = self.popvalue()
         w_exitfunc = self.popvalue()
         self.pushvalue(w_unroller)
-        unroller = self.space.interpclass_w(w_unroller)
-        is_app_exc = (unroller is not None and
-                      isinstance(unroller, SApplicationException))
-        if is_app_exc:
-            operr = unroller.operr
+        if isinstance(w_unroller, SApplicationException):
+            # app-level exception
+            operr = w_unroller.operr
             self.last_exception = operr
             w_traceback = self.space.wrap(operr.get_traceback())
             w_suppress = self.call_contextmanager_exit_function(
diff --git a/pypy/interpreter/pytraceback.py b/pypy/interpreter/pytraceback.py
--- a/pypy/interpreter/pytraceback.py
+++ b/pypy/interpreter/pytraceback.py
@@ -61,8 +61,7 @@
 
 def check_traceback(space, w_tb, msg):
     from pypy.interpreter.typedef import PyTraceback
-    tb = space.interpclass_w(w_tb)
-    if tb is None or not space.is_true(space.isinstance(tb,
+    if w_tb is None or not space.is_true(space.isinstance(w_tb,
             space.gettypeobject(PyTraceback.typedef))):
         raise OperationError(space.w_TypeError, space.wrap(msg))
-    return tb
+    return w_tb
diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -116,9 +116,8 @@
                return space.builtin
            if space.is_true(space.isinstance(w_builtin, space.w_dict)):
                 return module.Module(space, None, w_builtin)
-           builtin = space.interpclass_w(w_builtin)
-           if isinstance(builtin, module.Module):
-               return builtin
+           if isinstance(w_builtin, module.Module):
+               return w_builtin
        # no builtin! make a default one.  Give them None, at least.
        builtin = module.Module(space, None)
        space.setitem(builtin.w_dict, space.wrap('None'), space.w_None)
diff --git a/pypy/module/__builtin__/abstractinst.py b/pypy/module/__builtin__/abstractinst.py
--- a/pypy/module/__builtin__/abstractinst.py
+++ b/pypy/module/__builtin__/abstractinst.py
@@ -88,11 +88,9 @@
             return space.is_true(w_result)
 
     # -- case (old-style instance, old-style class)
-    oldstyleclass = space.interpclass_w(w_klass_or_tuple)
-    if isinstance(oldstyleclass, W_ClassObject):
-        oldstyleinst = space.interpclass_w(w_obj)
-        if isinstance(oldstyleinst, W_InstanceObject):
-            return oldstyleinst.w_class.is_subclass_of(oldstyleclass)
+    if isinstance(w_klass_or_tuple, W_ClassObject):
+        if isinstance(w_obj, W_InstanceObject):
+            return w_obj.w_class.is_subclass_of(w_klass_or_tuple)
     return _abstract_isinstance_w_helper(space, w_obj, w_klass_or_tuple)
 
 @jit.dont_look_inside
@@ -152,11 +150,9 @@
         return space.is_true(w_result)
 
     # -- case (old-style class, old-style class)
-    oldstylederived = space.interpclass_w(w_derived)
-    if isinstance(oldstylederived, W_ClassObject):
-        oldstyleklass = space.interpclass_w(w_klass_or_tuple)
-        if isinstance(oldstyleklass, W_ClassObject):
-            return oldstylederived.is_subclass_of(oldstyleklass)
+    if isinstance(w_derived, W_ClassObject):
+        if isinstance(w_klass_or_tuple, W_ClassObject):
+            return w_derived.is_subclass_of(w_klass_or_tuple)
     else:
         check_class(space, w_derived, "issubclass() arg 1 must be a class")
     # from here on, we are sure that w_derived is a class-like object
@@ -171,31 +167,26 @@
 # Exception helpers
 
 def exception_is_valid_obj_as_class_w(space, w_obj):
-    obj = space.interpclass_w(w_obj)
-    if isinstance(obj, W_ClassObject):
+    if isinstance(w_obj, W_ClassObject):
         return True
     return BaseObjSpace.exception_is_valid_obj_as_class_w(space, w_obj)
 
 def exception_is_valid_class_w(space, w_cls):
-    cls = space.interpclass_w(w_cls)
-    if isinstance(cls, W_ClassObject):
+    if isinstance(w_cls, W_ClassObject):
         return True
     return BaseObjSpace.exception_is_valid_class_w(space, w_cls)
 
 def exception_getclass(space, w_obj):
-    obj = space.interpclass_w(w_obj)
-    if isinstance(obj, W_InstanceObject):
-        return obj.w_class
+    if isinstance(w_obj, W_InstanceObject):
+        return w_obj.w_class
     return BaseObjSpace.exception_getclass(space, w_obj)
 
 def exception_issubclass_w(space, w_cls1, w_cls2):
-    cls1 = space.interpclass_w(w_cls1)
-    cls2 = space.interpclass_w(w_cls2)
-    if isinstance(cls1, W_ClassObject):
-        if isinstance(cls2, W_ClassObject):
-            return cls1.is_subclass_of(cls2)
+    if isinstance(w_cls1, W_ClassObject):
+        if isinstance(w_cls2, W_ClassObject):
+            return w_cls1.is_subclass_of(w_cls2)
         return False
-    if isinstance(cls2, W_ClassObject):
+    if isinstance(w_cls2, W_ClassObject):
         return False
     return BaseObjSpace.exception_issubclass_w(space, w_cls1, w_cls2)
 
diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -79,8 +79,7 @@
                                            space.wrap(' \t')),
                          "<string>", "eval")
 
-    codeobj = space.interpclass_w(w_code)
-    if not isinstance(codeobj, PyCode):
+    if not isinstance(w_code, PyCode):
         raise OperationError(space.w_TypeError,
               w('eval() arg 1 must be a string or code object'))
 
@@ -102,4 +101,4 @@
     # the gettopframe_nohidden()).  I bet no test fails, and it's a really
     # obscure case.
 
-    return codeobj.exec_code(space, w_globals, w_locals)
+    return w_code.exec_code(space, w_globals, w_locals)
diff --git a/pypy/module/__builtin__/interp_memoryview.py b/pypy/module/__builtin__/interp_memoryview.py
--- a/pypy/module/__builtin__/interp_memoryview.py
+++ b/pypy/module/__builtin__/interp_memoryview.py
@@ -22,11 +22,10 @@
 
     def _make_descr__cmp(name):
         def descr__cmp(self, space, w_other):
-            other = space.interpclass_w(w_other)
-            if isinstance(other, W_MemoryView):
+            if isinstance(w_other, W_MemoryView):
                 # xxx not the most efficient implementation
                 str1 = self.as_str()
-                str2 = other.as_str()
+                str2 = w_other.as_str()
                 return space.wrap(getattr(operator, name)(str1, str2))
 
             try:
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -90,15 +90,14 @@
             from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitive
             space = self.space
             cdata1 = self._cdata
-            other = space.interpclass_w(w_other)
-            if isinstance(other, W_CData):
+            if isinstance(w_other, W_CData):
                 if requires_ordering:
                     if (isinstance(self.ctype, W_CTypePrimitive) or
-                        isinstance(other.ctype, W_CTypePrimitive)):
+                        isinstance(w_other.ctype, W_CTypePrimitive)):
                         raise OperationError(space.w_TypeError,
                             space.wrap("cannot do comparison on a "
                                        "primitive cdata"))
-                cdata2 = other._cdata
+                cdata2 = w_other._cdata
             elif (misc.is_zero(space, w_other) and
                      not isinstance(self.ctype, W_CTypePrimitive)):
                 cdata2 = lltype.nullptr(rffi.CCHARP.TO)
@@ -246,10 +245,9 @@
 
     def sub(self, w_other):
         space = self.space
-        ob = space.interpclass_w(w_other)
-        if isinstance(ob, W_CData):
+        if isinstance(w_other, W_CData):
             from pypy.module._cffi_backend import ctypeptr, ctypearray
-            ct = ob.ctype
+            ct = w_other.ctype
             if isinstance(ct, ctypearray.W_CTypeArray):
                 ct = ct.ctptr
             #
@@ -261,7 +259,7 @@
                     self.ctype.name, ct.name)
             #
             diff = (rffi.cast(lltype.Signed, self._cdata) -
-                    rffi.cast(lltype.Signed, ob._cdata)) // ct.ctitem.size
+                    rffi.cast(lltype.Signed, w_other._cdata)) // ct.ctitem.size
             return space.wrap(diff)
         #
         return self._add_or_sub(w_other, -1)
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -80,12 +80,11 @@
 
     def _convert_error(self, expected, w_got):
         space = self.space
-        ob = space.interpclass_w(w_got)
-        if isinstance(ob, cdataobj.W_CData):
+        if isinstance(w_got, cdataobj.W_CData):
             return operationerrfmt(space.w_TypeError,
                                    "initializer for ctype '%s' must be a %s, "
                                    "not cdata '%s'", self.name, expected,
-                                   ob.ctype.name)
+                                   w_got.ctype.name)
         else:
             return operationerrfmt(space.w_TypeError,
                                    "initializer for ctype '%s' must be a %s, "
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -50,10 +50,9 @@
     def cast(self, w_ob):
         from pypy.module._cffi_backend import ctypeptr
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        if (isinstance(ob, cdataobj.W_CData) and
-               isinstance(ob.ctype, ctypeptr.W_CTypePtrOrArray)):
-            value = rffi.cast(lltype.Signed, ob._cdata)
+        if (isinstance(w_ob, cdataobj.W_CData) and
+               isinstance(w_ob.ctype, ctypeptr.W_CTypePtrOrArray)):
+            value = rffi.cast(lltype.Signed, w_ob._cdata)
             value = self._cast_result(value)
         elif space.isinstance_w(w_ob, space.w_str):
             value = self.cast_str(w_ob)
@@ -112,10 +111,9 @@
             s = space.str_w(w_ob)
             if len(s) == 1:
                 return s[0]
-        ob = space.interpclass_w(w_ob)
-        if (isinstance(ob, cdataobj.W_CData) and
-               isinstance(ob.ctype, W_CTypePrimitiveChar)):
-            return ob._cdata[0]
+        if (isinstance(w_ob, cdataobj.W_CData) and
+               isinstance(w_ob.ctype, W_CTypePrimitiveChar)):
+            return w_ob._cdata[0]
         raise self._convert_error("string of length 1", w_ob)
 
     def convert_from_object(self, cdata, w_ob):
@@ -146,10 +144,9 @@
             s = space.unicode_w(w_ob)
             if len(s) == 1:
                 return s[0]
-        ob = space.interpclass_w(w_ob)
-        if (isinstance(ob, cdataobj.W_CData) and
-               isinstance(ob.ctype, W_CTypePrimitiveUniChar)):
-            return rffi.cast(rffi.CWCHARP, ob._cdata)[0]
+        if (isinstance(w_ob, cdataobj.W_CData) and
+               isinstance(w_ob.ctype, W_CTypePrimitiveUniChar)):
+            return rffi.cast(rffi.CWCHARP, w_ob._cdata)[0]
         raise self._convert_error("unicode string of length 1", w_ob)
 
     def convert_from_object(self, cdata, w_ob):
@@ -270,13 +267,12 @@
 
     def cast(self, w_ob):
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        if isinstance(ob, cdataobj.W_CData):
-            if not isinstance(ob.ctype, W_CTypePrimitive):
+        if isinstance(w_ob, cdataobj.W_CData):
+            if not isinstance(w_ob.ctype, W_CTypePrimitive):
                 raise operationerrfmt(space.w_TypeError,
                                       "cannot cast ctype '%s' to ctype '%s'",
-                                      ob.ctype.name, self.name)
-            w_ob = ob.convert_to_object()
+                                      w_ob.ctype.name, self.name)
+            w_ob = w_ob.convert_to_object()
         #
         if space.isinstance_w(w_ob, space.w_str):
             value = self.cast_str(w_ob)
@@ -319,11 +315,10 @@
 
     def cast(self, w_ob):
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        if (isinstance(ob, cdataobj.W_CData) and
-                isinstance(ob.ctype, W_CTypePrimitiveLongDouble)):
-            w_cdata = self.convert_to_object(ob._cdata)
-            keepalive_until_here(ob)
+        if (isinstance(w_ob, cdataobj.W_CData) and
+                isinstance(w_ob.ctype, W_CTypePrimitiveLongDouble)):
+            w_cdata = self.convert_to_object(w_ob._cdata)
+            keepalive_until_here(w_ob)
             return w_cdata
         else:
             return W_CTypePrimitiveFloat.cast(self, w_ob)
@@ -356,11 +351,10 @@
 
     def convert_from_object(self, cdata, w_ob):
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        if (isinstance(ob, cdataobj.W_CData) and
-                isinstance(ob.ctype, W_CTypePrimitiveLongDouble)):
-            self._copy_longdouble(ob._cdata, cdata)
-            keepalive_until_here(ob)
+        if (isinstance(w_ob, cdataobj.W_CData) and
+                isinstance(w_ob.ctype, W_CTypePrimitiveLongDouble)):
+            self._copy_longdouble(w_ob._cdata, cdata)
+            keepalive_until_here(w_ob)
         else:
             value = space.float_w(space.float(w_ob))
             self._to_longdouble_and_write(value, cdata)
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -50,10 +50,9 @@
         if self.size < 0:
             return W_CType.cast(self, w_ob)
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        if (isinstance(ob, cdataobj.W_CData) and
-                isinstance(ob.ctype, W_CTypePtrOrArray)):
-            value = ob._cdata
+        if (isinstance(w_ob, cdataobj.W_CData) and
+                isinstance(w_ob.ctype, W_CTypePtrOrArray)):
+            value = w_ob._cdata
         else:
             value = misc.as_unsigned_long(space, w_ob, strict=False)
             value = rffi.cast(rffi.CCHARP, value)
@@ -152,14 +151,13 @@
 
     def convert_from_object(self, cdata, w_ob):
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        if not isinstance(ob, cdataobj.W_CData):
+        if not isinstance(w_ob, cdataobj.W_CData):
             if misc.is_zero(space, w_ob):
                 NULL = lltype.nullptr(rffi.CCHARP.TO)
                 rffi.cast(rffi.CCHARPP, cdata)[0] = NULL
                 return
             raise self._convert_error("cdata pointer", w_ob)
-        other = ob.ctype
+        other = w_ob.ctype
         if not isinstance(other, W_CTypePtrBase):
             from pypy.module._cffi_backend import ctypearray
             if isinstance(other, ctypearray.W_CTypeArray):
@@ -170,7 +168,7 @@
             if not (self.can_cast_anything or other.can_cast_anything):
                 raise self._convert_error("compatible pointer", w_ob)
 
-        rffi.cast(rffi.CCHARPP, cdata)[0] = ob._cdata
+        rffi.cast(rffi.CCHARPP, cdata)[0] = w_ob._cdata
 
     def _alignof(self):
         from pypy.module._cffi_backend import newtype
@@ -252,9 +250,8 @@
 
     def prepare_file(self, w_ob):
         from pypy.module._file.interp_file import W_File
-        ob = self.space.interpclass_w(w_ob)
-        if isinstance(ob, W_File):
-            return prepare_file_argument(self.space, ob)
+        if isinstance(w_ob, W_File):
+            return prepare_file_argument(self.space, w_ob)
         else:
             return lltype.nullptr(rffi.CCHARP.TO)
 
@@ -306,8 +303,7 @@
     def convert_argument_from_object(self, cdata, w_ob):
         from pypy.module._cffi_backend.ctypefunc import set_mustfree_flag
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        result = (not isinstance(ob, cdataobj.W_CData) and
+        result = (not isinstance(w_ob, cdataobj.W_CData) and
                   self._prepare_pointer_call_argument(w_ob, cdata))
         if result == 0:
             self.convert_from_object(cdata, w_ob)
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -80,11 +80,10 @@
 
     def _copy_from_same(self, cdata, w_ob):
         space = self.space
-        ob = space.interpclass_w(w_ob)
-        if isinstance(ob, cdataobj.W_CData):
-            if ob.ctype is self and self.size >= 0:
-                misc._raw_memcopy(ob._cdata, cdata, self.size)
-                keepalive_until_here(ob)
+        if isinstance(w_ob, cdataobj.W_CData):
+            if w_ob.ctype is self and self.size >= 0:
+                misc._raw_memcopy(w_ob._cdata, cdata, self.size)
+                keepalive_until_here(w_ob)
                 return True
         return False
 
diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -31,15 +31,14 @@
 # ____________________________________________________________
 
 def sizeof(space, w_obj):
-    ob = space.interpclass_w(w_obj)
-    if isinstance(ob, cdataobj.W_CData):
-        size = ob._sizeof()
-    elif isinstance(ob, ctypeobj.W_CType):
-        size = ob.size
+    if isinstance(w_obj, cdataobj.W_CData):
+        size = w_obj._sizeof()
+    elif isinstance(w_obj, ctypeobj.W_CType):
+        size = w_obj.size
         if size < 0:
             raise operationerrfmt(space.w_ValueError,
                                   "ctype '%s' is of unknown size",
-                                  ob.name)
+                                  w_obj.name)
     else:
         raise OperationError(space.w_TypeError,
                             space.wrap("expected a 'cdata' or 'ctype' object"))
diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -106,9 +106,8 @@
 def _is_a_float(space, w_ob):
     from pypy.module._cffi_backend.cdataobj import W_CData
     from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveFloat
-    ob = space.interpclass_w(w_ob)
-    if isinstance(ob, W_CData):
-        return isinstance(ob.ctype, W_CTypePrimitiveFloat)
+    if isinstance(w_ob, W_CData):
+        return isinstance(w_ob.ctype, W_CTypePrimitiveFloat)
     return space.isinstance_w(w_ob, space.w_float)
 
 def as_long_long(space, w_ob):
@@ -243,14 +242,14 @@
     from pypy.module._cffi_backend.cdataobj import W_CData
     from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveFloat
     from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveLongDouble
-    ob = space.interpclass_w(w_ob)
-    is_cdata = isinstance(ob, W_CData)
-    if is_cdata and isinstance(ob.ctype, W_CTypePrimitiveFloat):
-        if isinstance(ob.ctype, W_CTypePrimitiveLongDouble):
-            result = is_nonnull_longdouble(read_raw_longdouble_data(ob._cdata))
+    is_cdata = isinstance(w_ob, W_CData)
+    if is_cdata and isinstance(w_ob.ctype, W_CTypePrimitiveFloat):
+        if isinstance(w_ob.ctype, W_CTypePrimitiveLongDouble):
+            result = is_nonnull_longdouble(
+                read_raw_longdouble_data(w_ob._cdata))
         else:
-            result = read_raw_float_data(ob._cdata, ob.ctype.size) != 0.0
-        keepalive_until_here(ob)
+            result = read_raw_float_data(w_ob._cdata, w_ob.ctype.size) != 0.0
+        keepalive_until_here(w_ob)
         return result
     #
     if not is_cdata and space.lookup(w_ob, '__float__') is not None:
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -305,13 +305,12 @@
     from pypy.module._cffi_backend import ctypefunc
     fargs = []
     for w_farg in space.fixedview(w_fargs):
-        farg = space.interpclass_w(w_farg)
-        if not isinstance(farg, ctypeobj.W_CType):
+        if not isinstance(w_farg, ctypeobj.W_CType):
             raise OperationError(space.w_TypeError,
                 space.wrap("first arg must be a tuple of ctype objects"))
-        if isinstance(farg, ctypearray.W_CTypeArray):
-            farg = farg.ctptr
-        fargs.append(farg)
+        if isinstance(w_farg, ctypearray.W_CTypeArray):
+            w_farg = w_farg.ctptr
+        fargs.append(w_farg)
     #
     if ((fresult.size < 0 and not isinstance(fresult, ctypevoid.W_CTypeVoid))
             or isinstance(fresult, ctypearray.W_CTypeArray)):
diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -322,7 +322,7 @@
 
     def compare(self, w_other, op):
         space = self.space
-        if not isinstance(space.interpclass_w(w_other), W_Deque):
+        if not isinstance(w_other, W_Deque):
             return space.w_NotImplemented
         return space.compare_by_iteration(space.wrap(self), w_other, op)
     compare._annspecialcase_ = 'specialize:arg(2)'
diff --git a/pypy/module/_csv/interp_csv.py b/pypy/module/_csv/interp_csv.py
--- a/pypy/module/_csv/interp_csv.py
+++ b/pypy/module/_csv/interp_csv.py
@@ -60,8 +60,7 @@
             w_module = space.getbuiltinmodule('_csv')
             w_dialect = space.call_method(w_module, 'get_dialect', w_dialect)
 
-        dialect = space.interpclass_w(w_dialect)
-        if (isinstance(dialect, W_Dialect) and
+        if (isinstance(w_dialect, W_Dialect) and
             w_delimiter is None and
             w_doublequote is None and
             w_escapechar is None and
@@ -70,7 +69,7 @@
             w_quoting is None and
             w_skipinitialspace is None and
             w_strict is None):
-            return dialect
+            return w_dialect
 
         if w_delimiter is None:
             w_delimiter = _fetch(space, w_dialect, 'delimiter')
diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -321,9 +321,8 @@
     w = space.wrap
     if letter in TYPEMAP_PTR_LETTERS:
         # check for NULL ptr
-        datainstance = space.interpclass_w(w_arg)
-        if isinstance(datainstance, W_DataInstance):
-            ptr = datainstance.ll_buffer
+        if isinstance(w_arg, W_DataInstance):
+            ptr = w_arg.ll_buffer
         else:
             ptr = unwrap_truncate_int(rffi.VOIDP, space, w_arg)
         push_func(add_arg, argdesc, ptr)
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -424,11 +424,10 @@
 
     def _unwrap_object(self, space, w_obj):
         from pypy.module.cppyy.interp_cppyy import W_CPPInstance
-        obj = space.interpclass_w(w_obj)
-        if isinstance(obj, W_CPPInstance):
-            if capi.c_is_subtype(obj.cppclass, self.cppclass):
-                rawobject = obj.get_rawobject()
-                offset = capi.c_base_offset(obj.cppclass, self.cppclass, rawobject, 1)
+        if isinstance(w_obj, W_CPPInstance):
+            if capi.c_is_subtype(w_obj.cppclass, self.cppclass):
+                rawobject = w_obj.get_rawobject()
+                offset = capi.c_base_offset(w_obj.cppclass, self.cppclass, rawobject, 1)
                 obj_address = capi.direct_ptradd(rawobject, offset)
                 return rffi.cast(capi.C_OBJECT, obj_address)
         raise OperationError(space.w_TypeError,
@@ -498,10 +497,9 @@
 
     def finalize_call(self, space, w_obj, call_local):
         from pypy.module.cppyy.interp_cppyy import W_CPPInstance
-        obj = space.interpclass_w(w_obj)
-        assert isinstance(obj, W_CPPInstance)
+        assert isinstance(w_obj, W_CPPInstance)
         r = rffi.cast(rffi.VOIDPP, call_local)
-        obj._rawobject = rffi.cast(capi.C_OBJECT, r[0])
+        w_obj._rawobject = rffi.cast(capi.C_OBJECT, r[0])
 
 
 class StdStringConverter(InstanceConverter):
diff --git a/pypy/module/cppyy/test/test_zjit.py b/pypy/module/cppyy/test/test_zjit.py
--- a/pypy/module/cppyy/test/test_zjit.py
+++ b/pypy/module/cppyy/test/test_zjit.py
@@ -130,9 +130,6 @@
         return w_obj
     interp_w._annspecialcase_ = 'specialize:arg(1)'
 
-    def interpclass_w(self, w_obj):
-        return w_obj
-
     def buffer_w(self, w_obj):
         return FakeBuffer(w_obj)
 
diff --git a/pypy/module/cpyext/frameobject.py b/pypy/module/cpyext/frameobject.py
--- a/pypy/module/cpyext/frameobject.py
+++ b/pypy/module/cpyext/frameobject.py
@@ -85,5 +85,4 @@
 
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyTraceBack_Check(space, w_obj):
-    obj = space.interpclass_w(w_obj)
-    return obj is not None and isinstance(obj, PyTraceback)
+    return isinstance(w_obj, PyTraceback)
diff --git a/pypy/module/gc/referents.py b/pypy/module/gc/referents.py
--- a/pypy/module/gc/referents.py
+++ b/pypy/module/gc/referents.py
@@ -34,9 +34,8 @@
     return w_obj
 
 def unwrap(space, w_obj):
-    gcrefobj = space.interpclass_w(w_obj)
-    if isinstance(gcrefobj, W_GcRef):
-        gcref = gcrefobj.gcref
+    if isinstance(w_obj, W_GcRef):
+        gcref = w_obj.gcref
     else:
         gcref = rgc.cast_instance_to_gcref(w_obj)
     return gcref
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -992,11 +992,10 @@
 
     w_marshal = space.getbuiltinmodule('marshal')
     w_code = space.call_method(w_marshal, 'loads', space.wrap(strbuf))
-    pycode = space.interpclass_w(w_code)
-    if pycode is None or not isinstance(pycode, Code):
+    if not isinstance(w_code, Code):
         raise operationerrfmt(space.w_ImportError,
                               "Non-code object in %s", cpathname)
-    return pycode
+    return w_code
 
 @jit.dont_look_inside
 def load_compiled_module(space, w_modulename, w_mod, cpathname, magic,
diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -727,7 +727,7 @@
             stream.seek(8, 0)
             w_code = importing.read_compiled_module(
                     space, cpathname, stream.readall())
-            pycode = space.interpclass_w(w_code)
+            pycode = w_code
         finally:
             stream.close()
         assert type(pycode) is pypy.interpreter.pycode.PyCode
@@ -772,7 +772,7 @@
                                                   stream.readall())
         finally:
             stream.close()
-        pycode = space.interpclass_w(w_ret)
+        pycode = w_ret
         assert type(pycode) is pypy.interpreter.pycode.PyCode
         w_dic = space.newdict()
         pycode.exec_code(space, w_dic, w_dic)
@@ -911,7 +911,7 @@
                                                   stream.readall())
         finally:
             stream.close()
-        pycode = space.interpclass_w(w_ret)
+        pycode = w_ret
         assert type(pycode) is pypy.interpreter.pycode.PyCode
 
         cpathname = str(udir.join('cpathname.pyc'))
@@ -939,7 +939,7 @@
             stream.seek(8, 0)
             w_code = importing.read_compiled_module(space, cpathname,
                                                     stream.readall())
-            pycode = space.interpclass_w(w_code)
+            pycode = w_code
         finally:
             stream.close()
 
diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -823,10 +823,9 @@
     if n < 0:
         raise OperationError(space.w_ValueError, space.wrap("n must be >= 0"))
 
-    myiter = space.interpclass_w(w_iterable)
-    if isinstance(myiter, W_TeeIterable):     # optimization only
-        chained_list = myiter.chained_list
-        w_iterator = myiter.w_iterator
+    if isinstance(w_iterable, W_TeeIterable):     # optimization only
+        chained_list = w_iterable.chained_list
+        w_iterator = w_iterable.w_iterator
         iterators_w = [w_iterable] * n
         for i in range(1, n):
             iterators_w[i] = space.wrap(W_TeeIterable(space, w_iterator,
diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py
--- a/pypy/module/marshal/interp_marshal.py
+++ b/pypy/module/marshal/interp_marshal.py
@@ -11,9 +11,8 @@
 def dump(space, w_data, w_f, w_version):
     """Write the 'data' object into the open file 'f'."""
     # special case real files for performance
-    file = space.interpclass_w(w_f)
-    if isinstance(file, W_File):
-        writer = DirectStreamWriter(space, file)
+    if isinstance(w_f, W_File):
+        writer = DirectStreamWriter(space, w_f)
     else:
         writer = FileWriter(space, w_f)
     try:
@@ -36,9 +35,8 @@
 def load(space, w_f):
     """Read one value from the file 'f' and return it."""
     # special case real files for performance
-    file = space.interpclass_w(w_f)
-    if isinstance(file, W_File):
-        reader = DirectStreamReader(space, file)
+    if isinstance(w_f, W_File):
+        reader = DirectStreamReader(space, w_f)
     else:
         reader = FileReader(space, w_f)
     try:
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -129,17 +129,15 @@
         return space.lookup(w_obj, '__set__') is not None
 
     def get_and_call_args(space, w_descr, w_obj, args):
-        descr = space.interpclass_w(w_descr)
         # a special case for performance and to avoid infinite recursion
-        if isinstance(descr, Function):
-            return descr.call_obj_args(w_obj, args)
+        if isinstance(w_descr, Function):
+            return w_descr.call_obj_args(w_obj, args)
         else:
             w_impl = space.get(w_descr, w_obj)
             return space.call_args(w_impl, args)
 
     def get_and_call_function(space, w_descr, w_obj, *args_w):
-        descr = space.interpclass_w(w_descr)
-        typ = type(descr)
+        typ = type(w_descr)
         # a special case for performance and to avoid infinite recursion
         if typ is Function or typ is FunctionWithFixedCode:
             # isinstance(typ, Function) would not be correct here:
@@ -150,7 +148,7 @@
 
             # the fastcall paths are purely for performance, but the resulting
             # increase of speed is huge
-            return descr.funccall(w_obj, *args_w)
+            return w_descr.funccall(w_obj, *args_w)
         else:
             args = Arguments(space, list(args_w))
             w_impl = space.get(w_descr, w_obj)
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -867,9 +867,8 @@
                 # we have a data descriptor, which means the dictionary value
                 # (if any) has no relevance.
                 from pypy.interpreter.typedef import Member
-                descr = space.interpclass_w(w_descr)
-                if isinstance(descr, Member):    # it is a slot -- easy case
-                    selector = ("slot", SLOTS_STARTING_FROM + descr.index)
+                if isinstance(w_descr, Member):    # it is a slot -- easy case
+                    selector = ("slot", SLOTS_STARTING_FROM + w_descr.index)
             else:
                 # There is a non-data descriptor in the class.  If there is
                 # also a dict attribute, use the latter, caching its position.
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -256,11 +256,11 @@
 
     def unwrap(self, w_obj):
         """NOT_RPYTHON"""
-        if isinstance(w_obj, Wrappable):
-            return w_obj
         if isinstance(w_obj, model.W_Object):
             return w_obj.unwrap(self)
-        raise model.UnwrapError, "cannot unwrap: %r" % w_obj
+        if isinstance(w_obj, W_Root):
+            return w_obj
+        raise model.UnwrapError("cannot unwrap: %r" % w_obj)
 
     def newint(self, intval):
         return wrapint(self, intval)
diff --git a/pypy/tool/traceconfig.py b/pypy/tool/traceconfig.py
--- a/pypy/tool/traceconfig.py
+++ b/pypy/tool/traceconfig.py
@@ -10,7 +10,7 @@
         operations[name] = name
 
     # Remove list
-    for name in ["wrap", "unwrap", "interpclass_w"]:
+    for name in ["wrap", "unwrap"]:
         if name in operations:
             del operations[name]
 


More information about the pypy-commit mailing list