[pypy-commit] pypy kill-unary-multimethods: remove str_w as a multimethod

fijal noreply at buildbot.pypy.org
Fri Sep 16 18:22:04 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: kill-unary-multimethods
Changeset: r47299:2ec917d609d1
Date: 2011-09-16 11:48 +0200
http://bitbucket.org/pypy/pypy/changeset/2ec917d609d1/

Log:	remove str_w as a multimethod

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -3,7 +3,7 @@
 from pypy.interpreter.executioncontext import ExecutionContext, ActionFlag
 from pypy.interpreter.executioncontext import UserDelAction, FrameTraceAction
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.error import new_exception_class
+from pypy.interpreter.error import new_exception_class, typed_unwrap_error_msg
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.miscutils import ThreadLocals
 from pypy.tool.cache import Cache
@@ -186,6 +186,12 @@
     def _set_mapdict_storage_and_map(self, storage, map):
         raise NotImplementedError
 
+    # -------------------------------------------------------------------
+
+    def str_w(self, space):
+        w_msg = typed_unwrap_error_msg(space, "string", self)
+        raise OperationError(space.w_TypeError, w_msg)
+
 
 class Wrappable(W_Root):
     """A subclass of Wrappable is an internal, interpreter-level class
@@ -1210,6 +1216,9 @@
             return None
         return self.str_w(w_obj)
 
+    def str_w(self, w_obj):
+        return w_obj.str_w(self)
+
     def realstr_w(self, w_obj):
         # Like str_w, but only works if w_obj is really of type 'str'.
         if not self.is_true(self.isinstance(w_obj, self.w_str)):
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -458,3 +458,7 @@
     if module:
         space.setattr(w_exc, space.wrap("__module__"), space.wrap(module))
     return w_exc
+
+def typed_unwrap_error_msg(space, expected, w_obj):
+    type_name = space.type(w_obj).getname(space)
+    return space.wrap("expected %s, got %s object" % (expected, type_name))
diff --git a/pypy/objspace/std/default.py b/pypy/objspace/std/default.py
--- a/pypy/objspace/std/default.py
+++ b/pypy/objspace/std/default.py
@@ -1,6 +1,6 @@
 """Default implementation for some operation."""
 
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, typed_unwrap_error_msg
 from pypy.objspace.std.register_all import register_all
 from pypy.rlib import objectmodel
 
@@ -17,18 +17,10 @@
 def init__ANY(space, w_obj, __args__):
     pass
 
-def typed_unwrap_error_msg(space, expected, w_obj):
-    type_name = space.type(w_obj).getname(space)
-    return space.wrap("expected %s, got %s object" % (expected, type_name))
-
 def int_w__ANY(space,w_obj):
     raise OperationError(space.w_TypeError,
                          typed_unwrap_error_msg(space, "integer", w_obj))
 
-def str_w__ANY(space,w_obj):
-    raise OperationError(space.w_TypeError,
-                         typed_unwrap_error_msg(space, "string", w_obj))
-
 def float_w__ANY(space,w_obj):
     raise OperationError(space.w_TypeError,
                          typed_unwrap_error_msg(space, "float", w_obj))
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
@@ -452,7 +452,6 @@
     getnewargs = StdObjSpaceMultiMethod('__getnewargs__', 1)
     # special visible multimethods
     int_w   = StdObjSpaceMultiMethod('int_w', 1, [])     # returns an unwrapped int
-    str_w   = StdObjSpaceMultiMethod('str_w', 1, [])     # returns an unwrapped string
     float_w = StdObjSpaceMultiMethod('float_w', 1, [])   # returns an unwrapped float
     uint_w  = StdObjSpaceMultiMethod('uint_w', 1, [])    # returns an unwrapped unsigned int (r_uint)
     unicode_w = StdObjSpaceMultiMethod('unicode_w', 1, [])    # returns an unwrapped list of unicode characters
diff --git a/pypy/objspace/std/ropeobject.py b/pypy/objspace/std/ropeobject.py
--- a/pypy/objspace/std/ropeobject.py
+++ b/pypy/objspace/std/ropeobject.py
@@ -34,6 +34,7 @@
 
     def unwrap(w_self, space):
         return w_self._node.flatten_string()
+    str_w = unwrap
 
     def create_if_subclassed(w_self):
         if type(w_self) is W_RopeObject:
@@ -663,9 +664,6 @@
         return W_RopeObject(rope.concatenate(
             rope.multiply(zero, middle), node))
 
-def str_w__Rope(space, w_str):
-    return w_str._node.flatten_string()
-
 def hash__Rope(space, w_str):
     return wrapint(space, rope.hash_rope(w_str._node))
 
diff --git a/pypy/objspace/std/ropeunicodeobject.py b/pypy/objspace/std/ropeunicodeobject.py
--- a/pypy/objspace/std/ropeunicodeobject.py
+++ b/pypy/objspace/std/ropeunicodeobject.py
@@ -91,6 +91,9 @@
         # for testing
         return w_self._node.flatten_unicode()
 
+    def str_w(w_self, space):
+        return space.str_w(space.str(w_self))
+
     def create_if_subclassed(w_self):
         if type(w_self) is W_RopeUnicodeObject:
             return w_self
@@ -157,9 +160,6 @@
     assert isinstance(w_uni, W_RopeUnicodeObject) # help the annotator!
     return w_uni
 
-def str_w__RopeUnicode(space, w_uni):
-    return space.str_w(space.str(w_uni))
-
 def unicode_w__RopeUnicode(space, w_uni):
     return w_uni._node.flatten_unicode()
 
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
@@ -32,6 +32,9 @@
     def unwrap(self, space):
         return self.force()
 
+    def str_w(self, space):
+        return self.force()
+
 registerimplementation(W_StringBufferObject)
 
 # ____________________________________________________________
@@ -55,9 +58,6 @@
 def len__StringBuffer(space, w_self):
     return space.wrap(w_self.length)
 
-def str_w__StringBuffer(space, w_strbuf):
-    return w_strbuf.force()
-
 def add__StringBuffer_String(space, w_self, w_other):
     if w_self.builder.getlength() != w_self.length:
         builder = StringBuilder()
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -33,6 +33,9 @@
     def unwrap(w_self, space):
         return w_self._value
 
+    def str_w(w_self, space):
+        return w_self._value
+
 registerimplementation(W_StringObject)
 
 W_StringObject.EMPTY = W_StringObject('')
@@ -790,8 +793,6 @@
 
     return space.wrap("".join(buf))
 
-def str_w__String(space, w_str):
-    return w_str._value
 
 def hash__String(space, w_str):
     s = w_str._value
diff --git a/pypy/objspace/std/strjoinobject.py b/pypy/objspace/std/strjoinobject.py
--- a/pypy/objspace/std/strjoinobject.py
+++ b/pypy/objspace/std/strjoinobject.py
@@ -29,6 +29,7 @@
 
     def unwrap(w_self, space):
         return w_self.force()
+    str_w = unwrap
 
 registerimplementation(W_StringJoinObject)
 
@@ -45,9 +46,6 @@
         result += len(w_self.joined_strs[i])
     return space.wrap(result)
 
-def str_w__StringJoin(space, w_str):
-    return w_str.force()
-
 def add__StringJoin_StringJoin(space, w_self, w_other):
     if len(w_self.joined_strs) > w_self.until:
         w_self.force(True)
diff --git a/pypy/objspace/std/strsliceobject.py b/pypy/objspace/std/strsliceobject.py
--- a/pypy/objspace/std/strsliceobject.py
+++ b/pypy/objspace/std/strsliceobject.py
@@ -31,6 +31,9 @@
         w_self.stop = len(str)
         return str
 
+    def str_w(w_self, space):
+        return w_self.force()
+
     def __repr__(w_self):
         """ representation for debugging purposes """
         return "%s(%r[%d:%d])" % (w_self.__class__.__name__,
@@ -165,11 +168,6 @@
             return space.w_True
     return space.w_False
 
-
-def str_w__StringSlice(space, w_str):
-    return w_str.force()
-
-
 def getitem__StringSlice_ANY(space, w_str, w_index):
     ival = space.getindex_w(w_index, space.w_IndexError, "string index")
     slen = w_str.stop - w_str.start
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
@@ -40,6 +40,9 @@
             return w_self
         return W_UnicodeObject(w_self._value)
 
+    def str_w(w_self, space):
+        return space.str_w(space.str(w_self))
+
 W_UnicodeObject.EMPTY = W_UnicodeObject(u'')
 
 registerimplementation(W_UnicodeObject)
@@ -99,9 +102,6 @@
         return space.not_(result)
     return result
 
-def str_w__Unicode(space, w_uni):
-    return space.str_w(str__Unicode(space, w_uni))
-
 def unicode_w__Unicode(space, w_uni):
     return w_uni._value
 


More information about the pypy-commit mailing list