[pypy-commit] pypy refactor-str-types: Remove string types from multi-method table.

Manuel Jacob noreply at buildbot.pypy.org
Mon Jul 29 16:08:04 CEST 2013


Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r65786:808f2aea0f13
Date: 2013-07-29 16:00 +0200
http://bitbucket.org/pypy/pypy/changeset/808f2aea0f13/

Log:	Remove string types from multi-method table.

diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -2,9 +2,9 @@
 from pypy.interpreter.error import operationerrfmt, OperationError
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.objspace.std.bytesobject import str_typedef
+from pypy.objspace.std.bytesobject import W_BytesObject
 from pypy.objspace.std.floattype import float_typedef
-from pypy.objspace.std.unicodeobject import unicode_typedef, unicode_from_object
+from pypy.objspace.std.unicodeobject import W_UnicodeObject, unicode_from_object
 from pypy.objspace.std.inttype import int_typedef
 from pypy.objspace.std.complextype import complex_typedef
 from rpython.rlib.rarithmetic import LONG_BIT
@@ -682,12 +682,12 @@
     __module__ = "numpypy",
 )
 
-W_StringBox.typedef = TypeDef("string_", (str_typedef, W_CharacterBox.typedef),
+W_StringBox.typedef = TypeDef("string_", (W_BytesObject.typedef, W_CharacterBox.typedef),
     __module__ = "numpypy",
     __new__ = interp2app(W_StringBox.descr__new__string_box.im_func),
 )
 
-W_UnicodeBox.typedef = TypeDef("unicode_", (unicode_typedef, W_CharacterBox.typedef),
+W_UnicodeBox.typedef = TypeDef("unicode_", (W_UnicodeObject.typedef, W_CharacterBox.typedef),
     __module__ = "numpypy",
     __new__ = interp2app(W_UnicodeBox.descr__new__unicode_box.im_func),
 )
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -1,10 +1,10 @@
 """The builtin bytearray implementation"""
 
+from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.buffer import RWBuffer
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from pypy.interpreter.signature import Signature
-from pypy.objspace.std.model import W_Object, registerimplementation
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
@@ -16,7 +16,7 @@
 def _make_data(s):
     return [s[i] for i in range(len(s))]
 
-class W_BytearrayObject(W_Object, StringMethods):
+class W_BytearrayObject(W_Root, StringMethods):
     def __init__(w_self, data):
         w_self.data = data
 
@@ -378,7 +378,7 @@
 
 # ____________________________________________________________
 
-bytearray_typedef = W_BytearrayObject.typedef = StdTypeDef(
+W_BytearrayObject.typedef = StdTypeDef(
     "bytearray",
     __doc__ = '''bytearray() -> an empty bytearray
 bytearray(sequence) -> bytearray initialized from sequence\'s items
@@ -460,7 +460,6 @@
     remove = interp2app(W_BytearrayObject.descr_remove),
     reverse = interp2app(W_BytearrayObject.descr_reverse),
 )
-registerimplementation(W_BytearrayObject)
 
 init_signature = Signature(['source', 'encoding', 'errors'], None, None)
 init_defaults = [None, None, None]
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -1,12 +1,12 @@
 """The builtin str implementation"""
 
+from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.buffer import StringBuffer
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from pypy.objspace.std import newformat
 from pypy.objspace.std.basestringtype import basestring_typedef
 from pypy.objspace.std.formatting import mod_format
-from pypy.objspace.std.model import W_Object, registerimplementation
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
 from pypy.objspace.std.unicodeobject import (unicode_from_string,
@@ -16,7 +16,7 @@
 from rpython.rlib.rstring import StringBuilder, replace
 
 
-class W_AbstractBytesObject(W_Object):
+class W_AbstractBytesObject(W_Root):
     __slots__ = ()
 
     def is_w(self, space, w_other):
@@ -265,8 +265,6 @@
     # listview_str
     return [s for s in value]
 
-registerimplementation(W_BytesObject)
-
 W_BytesObject.EMPTY = W_BytesObject('')
 W_BytesObject.PREBUILT = [W_BytesObject(chr(i)) for i in range(256)]
 del i
@@ -294,7 +292,7 @@
     else:
         return W_BytesObject(c)
 
-str_typedef = W_BytesObject.typedef = StdTypeDef(
+W_BytesObject.typedef = StdTypeDef(
     "str", basestring_typedef,
     __new__ = interp2app(W_BytesObject.descr_new),
     __doc__ = '''str(object) -> string
diff --git a/pypy/objspace/std/model.py b/pypy/objspace/std/model.py
--- a/pypy/objspace/std/model.py
+++ b/pypy/objspace/std/model.py
@@ -36,13 +36,9 @@
             from pypy.objspace.std.inttype    import int_typedef
             from pypy.objspace.std.floattype  import float_typedef
             from pypy.objspace.std.complextype  import complex_typedef
-            from pypy.objspace.std.basestringtype import basestring_typedef
-            from pypy.objspace.std.bytesobject import str_typedef
-            from pypy.objspace.std.bytearrayobject import bytearray_typedef
             from pypy.objspace.std.typeobject   import type_typedef
             from pypy.objspace.std.slicetype  import slice_typedef
             from pypy.objspace.std.longtype   import long_typedef
-            from pypy.objspace.std.unicodeobject import unicode_typedef
             from pypy.objspace.std.nonetype import none_typedef
         self.pythontypes = [value for key, value in result.__dict__.items()
                             if not key.startswith('_')]   # don't look
@@ -59,6 +55,7 @@
         from pypy.objspace.std import listobject
         from pypy.objspace.std import dictmultiobject
         from pypy.objspace.std import setobject
+        from pypy.objspace.std import basestringtype
         from pypy.objspace.std import bytesobject
         from pypy.objspace.std import bytearrayobject
         from pypy.objspace.std import typeobject
@@ -81,6 +78,10 @@
         self.pythontypes.append(setobject.W_SetObject.typedef)
         self.pythontypes.append(setobject.W_FrozensetObject.typedef)
         self.pythontypes.append(iterobject.W_AbstractSeqIterObject.typedef)
+        self.pythontypes.append(basestringtype.basestring_typedef)
+        self.pythontypes.append(bytesobject.W_BytesObject.typedef)
+        self.pythontypes.append(bytearrayobject.W_BytearrayObject.typedef)
+        self.pythontypes.append(unicodeobject.W_UnicodeObject.typedef)
 
         # the set of implementation types
         self.typeorder = {
@@ -88,14 +89,11 @@
             boolobject.W_BoolObject: [],
             intobject.W_IntObject: [],
             floatobject.W_FloatObject: [],
-            bytesobject.W_BytesObject: [],
-            bytearrayobject.W_BytearrayObject: [],
             typeobject.W_TypeObject: [],
             sliceobject.W_SliceObject: [],
             longobject.W_LongObject: [],
             noneobject.W_NoneObject: [],
             complexobject.W_ComplexObject: [],
-            unicodeobject.W_UnicodeObject: [],
             pypy.interpreter.pycode.PyCode: [],
             pypy.interpreter.special.Ellipsis: [],
             }
diff --git a/pypy/objspace/std/strbufobject.py b/pypy/objspace/std/strbufobject.py
--- a/pypy/objspace/std/strbufobject.py
+++ b/pypy/objspace/std/strbufobject.py
@@ -1,12 +1,8 @@
-from pypy.objspace.std.model import registerimplementation, W_Object
-from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.bytesobject import W_AbstractBytesObject, W_BytesObject
 from rpython.rlib.rstring import StringBuilder
 from pypy.interpreter.buffer import Buffer
 
 class W_StringBufferObject(W_AbstractBytesObject):
-    from pypy.objspace.std.bytesobject import str_typedef as typedef
-
     w_str = None
 
     def __init__(self, builder):
@@ -34,7 +30,7 @@
     def str_w(self, space):
         return self.force()
 
-registerimplementation(W_StringBufferObject)
+W_StringBufferObject.typedef = W_BytesObject.typedef
 
 # ____________________________________________________________
 
@@ -64,4 +60,3 @@
     return w_self
 
 from pypy.objspace.std import bytesobject
-register_all(vars(), bytesobject)
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -1,13 +1,13 @@
 """The builtin unicode implementation"""
 
 from pypy.interpreter import unicodehelper
+from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from pypy.module.unicodedata import unicodedb
 from pypy.objspace.std import newformat
 from pypy.objspace.std.basestringtype import basestring_typedef
 from pypy.objspace.std.formatting import mod_format
-from pypy.objspace.std.model import W_Object, registerimplementation
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
 from rpython.rlib.objectmodel import compute_hash, compute_unique_id
@@ -20,7 +20,7 @@
            'unicode_from_string', 'unicode_to_decimal_w']
 
 
-class W_UnicodeObject(W_Object, StringMethods):
+class W_UnicodeObject(W_Root, StringMethods):
     _immutable_fields_ = ['_value']
 
     def __init__(w_self, unistr):
@@ -404,7 +404,7 @@
 
 # ____________________________________________________________
 
-unicode_typedef = W_UnicodeObject.typedef = StdTypeDef(
+W_UnicodeObject.typedef = StdTypeDef(
     "unicode", basestring_typedef,
     __new__ = interp2app(descr_new_),
     __doc__ = '''unicode(string [, encoding[, errors]]) -> object
@@ -483,8 +483,6 @@
         interp2app(W_UnicodeObject.descr_formatter_field_name_split),
 )
 
-unitypedef = unicode_typedef
-
 
 def _create_list_from_unicode(value):
     # need this helper function to allow the jit to look inside and inline
@@ -494,8 +492,6 @@
 
 W_UnicodeObject.EMPTY = W_UnicodeObject(u'')
 
-registerimplementation(W_UnicodeObject)
-
 # Helper for converting int/long
 def unicode_to_decimal_w(space, w_unistr):
     if not isinstance(w_unistr, W_UnicodeObject):


More information about the pypy-commit mailing list