[pypy-commit] pypy py3.5-newtext: more fixes

arigo pypy.commits at gmail.com
Wed Feb 15 13:14:03 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5-newtext
Changeset: r90157:c851c9167f8e
Date: 2017-02-15 19:13 +0100
http://bitbucket.org/pypy/pypy/changeset/c851c9167f8e/

Log:	more fixes

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1517,6 +1517,9 @@
                 return None
             code = 's*'
         if code == 's*':
+            # NOTE: 's*' is almost not used any more inside CPython 3.5.
+            # Try not to use it pointlessly: it accepts unicodes, which
+            # most API in CPython 3.x no longer do.
             if self.isinstance_w(w_obj, self.w_bytes):
                 return StringBuffer(w_obj.bytes_w(self))
             if self.isinstance_w(w_obj, self.w_unicode):
@@ -1526,6 +1529,9 @@
             except BufferInterfaceNotFound:
                 self._getarg_error("bytes or buffer", w_obj)
         elif code == 's#':
+            # NOTE: 's#' is almost not used any more inside CPython 3.5.
+            # Try not to use it pointlessly: it accepts unicodes, which
+            # most API in CPython 3.x no longer do.
             if self.isinstance_w(w_obj, self.w_bytes):
                 return w_obj.bytes_w(self)
             if self.isinstance_w(w_obj, self.w_unicode):
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -1123,7 +1123,7 @@
         if not space.config.translating:
             fn.add_to_table()
         if gateway.as_classmethod:
-            fn = ClassMethod(space.wrap(fn))
+            fn = ClassMethod(fn)
         #
         from pypy.module.sys.vm import exc_info
         if code._bltin is exc_info:
diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -83,7 +83,7 @@
         w_dict = self.w_dict
         space.setitem(w_dict, space.new_interned_str('__name__'), w_name)
         space.setitem(w_dict, space.new_interned_str('__doc__'), w_doc)
-        init_extra_module_attrs(space, space.wrap(self))
+        init_extra_module_attrs(space, self)
 
     def descr__reduce__(self, space):
         w_name = space.finditem(self.w_dict, space.newtext('__name__'))
diff --git a/pypy/interpreter/nestedscope.py b/pypy/interpreter/nestedscope.py
--- a/pypy/interpreter/nestedscope.py
+++ b/pypy/interpreter/nestedscope.py
@@ -46,7 +46,7 @@
         if not isinstance(w_other, Cell):
             return space.w_NotImplemented
         if self.w_value is None or w_other.w_value is None:
-            return space.wrap(self.w_value == w_other.w_value)
+            return space.newbool(self.w_value == w_other.w_value)
         return space.eq(self.w_value, w_other.w_value)
 
     def descr__reduce__(self, space):
diff --git a/pypy/interpreter/pycompiler.py b/pypy/interpreter/pycompiler.py
--- a/pypy/interpreter/pycompiler.py
+++ b/pypy/interpreter/pycompiler.py
@@ -140,7 +140,7 @@
             validate.validate_ast(self.space, node)
         except validate.ValidationError as e:
             raise OperationError(self.space.w_ValueError,
-                                 self.space.wrap(e.message))
+                                 self.space.newtext(e.message))
 
     def compile_to_ast(self, source, filename, mode, flags):
         info = pyparse.CompileInfo(filename, mode, flags)
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -533,7 +533,7 @@
         i = varindex - len(self.pycode.co_cellvars)
         assert i >= 0
         name = self.pycode.co_freevars[i]
-        w_value = space.finditem(self.debugdata.w_locals, space.wrap(name))
+        w_value = space.finditem(self.debugdata.w_locals, space.newtext(name))
         if w_value is None:
             self.LOAD_DEREF(varindex, next_instr)
         else:
@@ -726,7 +726,7 @@
         operror = OperationError(w_type, w_value)
         operror.normalize_exception(space)
         operror.set_cause(space, w_cause)
-        tb = space.getattr(w_value, space.wrap('__traceback__'))
+        tb = space.getattr(w_value, space.newtext('__traceback__'))
         if not space.is_w(tb, space.w_None):
             operror.set_traceback(tb)
         raise operror
@@ -1584,11 +1584,11 @@
                 raise oefmt(space.w_TypeError,
                             "'async for' received an invalid object "
                             "from __aiter__: %T", w_iter)
-            space.warn(space.wrap(
-                u"'%s' implements legacy __aiter__ protocol; "
-                u"__aiter__ should return an asynchronous "
-                u"iterator, not awaitable" %
-                    space.type(w_obj).name.decode('utf-8')),
+            space.warn(space.newtext(
+                "'%s' implements legacy __aiter__ protocol; "
+                "__aiter__ should return an asynchronous "
+                "iterator, not awaitable" %
+                    space.type(w_obj).name),
                 space.w_PendingDeprecationWarning)
         self.pushvalue(w_awaitable)
 
diff --git a/pypy/interpreter/pytraceback.py b/pypy/interpreter/pytraceback.py
--- a/pypy/interpreter/pytraceback.py
+++ b/pypy/interpreter/pytraceback.py
@@ -50,7 +50,7 @@
         self.next = space.interp_w(PyTraceback, w_next, can_be_None=True)
 
     def descr__dir__(self, space):
-        return space.newlist([space.wrap(n) for n in
+        return space.newlist([space.newtext(n) for n in
             ['tb_frame', 'tb_next', 'tb_lasti', 'tb_lineno']])
 
 
diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py
--- a/pypy/module/mmap/interp_mmap.py
+++ b/pypy/module/mmap/interp_mmap.py
@@ -53,7 +53,7 @@
     def find(self, w_tofind, w_start=None, w_end=None):
         self.check_valid()
         space = self.space
-        tofind = space.getarg_w('s#', w_tofind)
+        tofind = space.getarg_w('y*', w_tofind)
         if w_start is None:
             start = self.mmap.pos
         else:
@@ -67,7 +67,7 @@
     def rfind(self, w_tofind, w_start=None, w_end=None):
         self.check_valid()
         space = self.space
-        tofind = space.getarg_w('s#', w_tofind)
+        tofind = space.getarg_w('y*', w_tofind)
         if w_start is None:
             start = self.mmap.pos
         else:
@@ -99,7 +99,7 @@
 
     def write(self, w_data):
         self.check_valid()
-        data = self.space.getarg_w('s#', w_data)
+        data = self.space.getarg_w('y*', w_data)
         self.check_writeable()
         try:
             self.mmap.write(data)
diff --git a/pypy/module/struct/interp_struct.py b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -102,7 +102,7 @@
     return do_unpack(space, format, w_str)
 
 def do_unpack(space, format, w_str):
-    buf = space.getarg_w('s*', w_str)
+    buf = space.getarg_w('y*', w_str)
     return _unpack(space, format, buf)
 
 
diff --git a/pypy/module/struct/test/test_struct.py b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -264,7 +264,8 @@
         assert pack(">?", False) == b'\x00'
         assert pack("@?", True) == b'\x01'
         assert pack("@?", False) == b'\x00'
-        assert self.struct.unpack("?", 'X')[0] is True
+        assert self.struct.unpack("?", b'X')[0] is True
+        raises(TypeError, self.struct.unpack, "?", 'X')
 
     def test_transitiveness(self):
         c = b'a'


More information about the pypy-commit mailing list