[pypy-commit] pypy space-newtext: To make this branch more incrementally mergeable to trunk, add BACKCOMPAT

arigo pypy.commits at gmail.com
Mon Feb 13 06:42:26 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: space-newtext
Changeset: r90079:3b763661eb95
Date: 2017-02-13 12:11 +0100
http://bitbucket.org/pypy/pypy/changeset/3b763661eb95/

Log:	To make this branch more incrementally mergeable to trunk, add
	BACKCOMPAT comments and keep it working with both the current and
	new ways

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -77,8 +77,7 @@
 
     def getname(self, space):
         try:
-            # YYY should be text_w?
-            return space.bytes_w(space.getattr(self, space.newtext('__name__')))
+            return space.text_w(space.getattr(self, space.newtext('__name__')))
         except OperationError as e:
             if e.match(space, space.w_TypeError) or e.match(space, space.w_AttributeError):
                 return '?'
@@ -842,7 +841,7 @@
 
     def new_interned_w_str(self, w_s):
         assert isinstance(w_s, W_Root)   # and is not None
-        s = self.bytes_w(w_s)
+        s = self.text_w(w_s)
         if not we_are_translated():
             assert type(s) is str
         w_s1 = self.interned_strings.get(s)
@@ -857,7 +856,7 @@
             assert type(s) is str
         w_s1 = self.interned_strings.get(s)
         if w_s1 is None:
-            w_s1 = self.newbytes(s)
+            w_s1 = self.newtext(s)
             self.interned_strings.set(s, w_s1)
         return w_s1
 
@@ -1608,12 +1607,17 @@
         return None if self.is_none(w_obj) else self.bytes_w(w_obj)
 
     def bytes_w(self, w_obj):
+        "Takes a bytes object and returns an unwrapped RPython bytestring."
         return w_obj.str_w(self)
-    text_w = bytes_w # equivalent to identifier_w on Python3
 
-    @not_rpython
+    def text_w(self, w_obj):
+        """Takes a string object (unicode in Python 3) and returns an
+        unwrapped RPython bytestring."""
+        return w_obj.str_w(self)
+
+    #@not_rpython    BACKCOMPAT: should be replaced with bytes_w or text_w
     def str_w(self, w_obj):
-        # XXX there are still some tests that call it
+        """For tests only."""
         return self.bytes_w(w_obj)
 
 
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
@@ -89,9 +89,9 @@
         for typedef, cls in builtin_type_classes.items():
             w_type = self.gettypeobject(typedef)
             self.builtin_types[typedef.name] = w_type
-            if typedef.name != "str":
+            if 1: # typedef.name != "str":      BACKCOMPAT
                 setattr(self, 'w_' + typedef.name, w_type)
-            else:
+            if typedef.name == "str":
                 self.w_bytes = w_type
             self._interplevel_classes[w_type] = cls
         self.w_text = self.w_bytes # this is w_unicode on Py3
@@ -133,7 +133,11 @@
         assert typedef is not None
         return self.fromcache(TypeCache).getorbuild(typedef)
 
-    @not_rpython # only for tests
+    # BACKCOMPAT: this function is still accepted for backward
+    # compatibility, but its usage should be progressively removed
+    # everywhere apart from tests.
+    #@not_rpython # only for tests
+    @specialize.argtype(1)
     def wrap(self, x):
         """ Wraps the Python value 'x' into one of the wrapper classes. This
         should only be used for tests, in real code you need to use the
@@ -166,6 +170,12 @@
         if is_valid_int(x):
             return self.newint(x)
 
+        return self._wrap_not_rpython(x)
+
+    def _wrap_not_rpython(self, x):
+        "NOT_RPYTHON"
+        # _____ this code is here to support testing only _____
+
         # wrap() of a container works on CPython, but the code is
         # not RPython.  Don't use -- it is kept around mostly for tests.
         # Use instead newdict(), newlist(), newtuple().


More information about the pypy-commit mailing list