[pypy-commit] pypy py3.5: Remove some space.wrap()

arigo pypy.commits at gmail.com
Tue Feb 21 03:54:04 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r90241:04c87a175ddd
Date: 2017-02-21 09:33 +0100
http://bitbucket.org/pypy/pypy/changeset/04c87a175ddd/

Log:	Remove some space.wrap()

diff --git a/pypy/interpreter/pyparser/error.py b/pypy/interpreter/pyparser/error.py
--- a/pypy/interpreter/pyparser/error.py
+++ b/pypy/interpreter/pyparser/error.py
@@ -31,7 +31,7 @@
             w_text = space.newunicode(text)
         if self.filename is not None:
             w_filename = space.wrap_fsdecoded(self.filename)
-        return space.newtuple([space.wrap(self.msg),
+        return space.newtuple([space.newtext(self.msg),
                                space.newtuple([w_filename,
                                                space.newint(self.lineno),
                                                space.newint(offset),
diff --git a/pypy/module/__pypy__/interp_stderrprinter.py b/pypy/module/__pypy__/interp_stderrprinter.py
--- a/pypy/module/__pypy__/interp_stderrprinter.py
+++ b/pypy/module/__pypy__/interp_stderrprinter.py
@@ -17,21 +17,21 @@
 
     def descr_repr(self, space):
         addrstring = unicode(self.getaddrstring(space))
-        return space.wrap(u"<StdErrPrinter(fd=%d) object at 0x%s>" %
-                          (self.fd, addrstring))
+        return space.newunicode(u"<StdErrPrinter(fd=%d) object at 0x%s>" %
+                                (self.fd, addrstring))
 
     def descr_noop(self, space):
         pass
 
     def descr_fileno(self, space):
-        return space.wrap(self.fd)
+        return space.newint(self.fd)
 
     def descr_isatty(self, space):
         try:
             res = os.isatty(self.fd)
         except OSError as e:
             raise wrap_oserror(space, e)
-        return space.wrap(res)
+        return space.newbool(res)
 
     def descr_write(self, space, w_data):
         # Encode to UTF-8-nosg.
@@ -43,16 +43,16 @@
             if e.errno == errno.EAGAIN:
                 return space.w_None
             raise wrap_oserror(space, e)
-        return space.wrap(n)
+        return space.newint(n)
 
     def descr_get_closed(self, space):
-        return space.wrap(False)
+        return space.newbool(False)
 
     def descr_get_encoding(self, space):
         return space.w_None
 
     def descr_get_mode(self, space):
-        return space.wrap(u'w')
+        return space.newtext('w')
 
 
 W_StdErrPrinter.typedef = TypeDef("StdErrPrinter",
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
@@ -419,7 +419,7 @@
         if fd < 0:
             raise oefmt(space.w_ValueError, "file has no OS file descriptor")
         fd = os.dup(fd)
-        mode = space.str_w(space.getattr(w_fileobj, space.wrap("mode")))
+        mode = space.text_w(space.getattr(w_fileobj, space.newtext("mode")))
         try:
             w_fileobj.cffi_fileobj = CffiFileObj(fd, mode)
         except OSError as e:
diff --git a/pypy/module/cpyext/dictproxyobject.py b/pypy/module/cpyext/dictproxyobject.py
--- a/pypy/module/cpyext/dictproxyobject.py
+++ b/pypy/module/cpyext/dictproxyobject.py
@@ -7,4 +7,4 @@
 
 @cpython_api([PyObject], PyObject)
 def PyDictProxy_New(space, w_dict):
-    return space.wrap(W_DictProxyObject(w_dict))
+    return W_DictProxyObject(w_dict)
diff --git a/pypy/module/cpyext/exception.py b/pypy/module/cpyext/exception.py
--- a/pypy/module/cpyext/exception.py
+++ b/pypy/module/cpyext/exception.py
@@ -15,7 +15,7 @@
     """Return the traceback associated with the exception as a new reference, as
     accessible from Python through __traceback__.  If there is no
     traceback associated, this returns NULL."""
-    w_tb = space.getattr(w_exc, space.wrap('__traceback__'))
+    w_tb = space.getattr(w_exc, space.newtext('__traceback__'))
     if space.is_none(w_tb):
         return None
     return w_tb
@@ -25,7 +25,7 @@
 def PyException_SetTraceback(space, w_exc, w_tb):
     """Set the traceback associated with the exception to tb.  Use Py_None to
     clear it."""
-    space.setattr(w_exc, space.wrap('__traceback__'), w_tb)
+    space.setattr(w_exc, space.newtext('__traceback__'), w_tb)
     return 0
 
 
@@ -35,7 +35,7 @@
     raised) associated with the exception as a new reference, as accessible from
     Python through __context__.  If there is no context associated, this
     returns NULL."""
-    w_ctx = space.getattr(w_exc, space.wrap('__context__'))
+    w_ctx = space.getattr(w_exc, space.newtext('__context__'))
     if space.is_none(w_ctx):
         return None
     return w_ctx
@@ -51,7 +51,7 @@
         Py_DecRef(space, ctx)
     else:
         w_ctx = space.w_None
-    space.setattr(w_exc, space.wrap('__context__'), w_ctx)
+    space.setattr(w_exc, space.newtext('__context__'), w_ctx)
 
 @cpython_api([PyObject], PyObject)
 def PyException_GetCause(space, w_exc):
@@ -59,7 +59,7 @@
     associated with the exception as a new reference, as accessible from Python
     through __cause__.  If there is no cause associated, this returns
     NULL."""
-    w_cause = space.getattr(w_exc, space.wrap('__cause__'))
+    w_cause = space.getattr(w_exc, space.newtext('__cause__'))
     if space.is_none(w_cause):
         return None
     return w_cause
@@ -75,5 +75,5 @@
         Py_DecRef(space, cause)
     else:
         w_cause = space.w_None
-    space.setattr(w_exc, space.wrap('__cause__'), w_cause)
+    space.setattr(w_exc, space.newtext('__cause__'), w_cause)
 
diff --git a/pypy/module/cpyext/structmember.py b/pypy/module/cpyext/structmember.py
--- a/pypy/module/cpyext/structmember.py
+++ b/pypy/module/cpyext/structmember.py
@@ -121,7 +121,7 @@
             casted = rffi.cast(lltyp, value)
             if range_checking:
                 if rffi.cast(lltype.typeOf(value), casted) != value:
-                    space.warn(space.wrap("structmember: truncation of value"),
+                    space.warn(space.newtext("structmember: truncation of value"),
                                space.w_RuntimeWarning)
             array[0] = casted
             return 0
diff --git a/pypy/module/posix/interp_scandir.py b/pypy/module/posix/interp_scandir.py
--- a/pypy/module/posix/interp_scandir.py
+++ b/pypy/module/posix/interp_scandir.py
@@ -58,7 +58,7 @@
             rposix_scandir.closedir(self.dirp)
 
     def iter_w(self):
-        return self.space.wrap(self)
+        return self
 
     def fail(self, err=None):
         dirp = self.dirp
@@ -99,7 +99,7 @@
         finally:
             self._in_next = False
         direntry = W_DirEntry(self, name, known_type, inode)
-        return space.wrap(direntry)
+        return direntry
 
 
 W_ScandirIterator.typedef = TypeDef(
@@ -139,7 +139,7 @@
 
     def descr_repr(self, space):
         u = space.unicode_w(space.repr(self.w_name))
-        return space.wrap(u"<DirEntry %s>" % u)
+        return space.newunicode(u"<DirEntry %s>" % u)
 
     def fget_name(self, space):
         return self.w_name
@@ -272,16 +272,16 @@
     @unwrap_spec(follow_symlinks=bool)
     def descr_is_dir(self, space, __kwonly__, follow_symlinks=True):
         """return True if the entry is a directory; cached per entry"""
-        return space.wrap(self.is_dir(follow_symlinks))
+        return space.newbool(self.is_dir(follow_symlinks))
 
     @unwrap_spec(follow_symlinks=bool)
     def descr_is_file(self, space, __kwonly__, follow_symlinks=True):
         """return True if the entry is a file; cached per entry"""
-        return space.wrap(self.is_file(follow_symlinks))
+        return space.newbool(self.is_file(follow_symlinks))
 
     def descr_is_symlink(self, space):
         """return True if the entry is a symbolic link; cached per entry"""
-        return space.wrap(self.is_symlink())
+        return space.newbool(self.is_symlink())
 
     @unwrap_spec(follow_symlinks=bool)
     def descr_stat(self, space, __kwonly__, follow_symlinks=True):
@@ -294,7 +294,7 @@
         return build_stat_result(space, st)
 
     def descr_inode(self, space):
-        return space.wrap(self.inode)
+        return space.newint(self.inode)
 
 
 W_DirEntry.typedef = TypeDef(
diff --git a/pypy/module/signal/interp_signal.py b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -394,7 +394,7 @@
         # the signal isn't a member of the mask or the signal was
         # invalid, and an invalid signal must have been our fault in
         # constructing the loop boundaries.
-        signals_w.append(space.wrap(sig))
+        signals_w.append(space.newint(sig))
     return space.call_function(space.w_set, space.newtuple(signals_w))
 
 def sigwait(space, w_signals):
@@ -404,7 +404,7 @@
             if ret != 0:
                 raise exception_from_saved_errno(space, space.w_OSError)
             signum = signum_ptr[0]
-    return space.wrap(signum)
+    return space.newint(signum)
 
 def sigpending(space):
     with lltype.scoped_alloc(c_sigset_t.TO) as mask:
diff --git a/pypy/module/sys/system.py b/pypy/module/sys/system.py
--- a/pypy/module/sys/system.py
+++ b/pypy/module/sys/system.py
@@ -93,15 +93,15 @@
     HASH_WIDTH = 8 * rffi.sizeof(lltype.Signed)
     HASH_CUTOFF = 0
     info_w = [
-        space.wrap(HASH_WIDTH),
-        space.wrap(HASH_MODULUS),
-        space.wrap(HASH_INF),
-        space.wrap(HASH_NAN),
-        space.wrap(HASH_IMAG),
-        space.wrap(HASH_ALGORITHM),
-        space.wrap(HASH_HASH_BITS),
-        space.wrap(HASH_SEED_BITS),
-        space.wrap(HASH_CUTOFF),
+        space.newint(HASH_WIDTH),
+        space.newint(HASH_MODULUS),
+        space.newint(HASH_INF),
+        space.newint(HASH_NAN),
+        space.newint(HASH_IMAG),
+        space.newtext(HASH_ALGORITHM),
+        space.newint(HASH_HASH_BITS),
+        space.newint(HASH_SEED_BITS),
+        space.newint(HASH_CUTOFF),
     ]
     w_hash_info = app.wget(space, "hash_info")
     return space.call_function(w_hash_info, space.newtuple(info_w))
@@ -114,10 +114,10 @@
         return None
     from rpython.rlib import rthread
     if rthread.RPYTHREAD_NAME == "pthread":
-        w_lock = space.wrap("semaphore" if rthread.USE_SEMAPHORES
-                            else "mutex+cond")
+        w_lock = space.newtext("semaphore" if rthread.USE_SEMAPHORES
+                               else "mutex+cond")
         if rthread.CS_GNU_LIBPTHREAD_VERSION is not None:
-            w_version = space.wrap(
+            w_version = space.newtext(
                 os.confstr(rthread.CS_GNU_LIBPTHREAD_VERSION))
         else:
             w_version = space.w_None
@@ -125,7 +125,7 @@
         w_lock = space.w_None
         w_version = space.w_None
     info_w = [
-        space.wrap(rthread.RPYTHREAD_NAME),
+        space.newtext(rthread.RPYTHREAD_NAME),
         w_lock, w_version,
     ]
     w_thread_info = app.wget(space, "thread_info")
diff --git a/pypy/module/zipimport/interp_zipimport.py b/pypy/module/zipimport/interp_zipimport.py
--- a/pypy/module/zipimport/interp_zipimport.py
+++ b/pypy/module/zipimport/interp_zipimport.py
@@ -329,7 +329,7 @@
                     w_data = self.get_data(space, fname)
                     # XXX CPython does not handle the coding cookie either.
                     return space.call_method(w_data, "decode",
-                                             space.wrap("utf-8"))
+                                             space.newtext("utf-8"))
                 else:
                     found = True
         if found:
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
@@ -541,7 +541,7 @@
             if w_srctype is space.w_list or w_srctype is space.w_tuple:
                 length = space.len_w(w_source)
                 if jit.isconstant(length) and length == 1:
-                    w_item = space.getitem(w_source, space.wrap(0))
+                    w_item = space.getitem(w_source, space.newint(0))
                     value = getbytevalue(space, w_item)
                     return W_BytesObject(value)
             else:
@@ -578,7 +578,7 @@
 
     def descr_str(self, space):
         if space.sys.get_flag('bytes_warning'):
-            space.warn(space.wrap("str() on a bytes instance"),
+            space.warn(space.newtext("str() on a bytes instance"),
                        space.w_BytesWarning)
         return self.descr_repr(space)
 
diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py
--- a/pypy/objspace/std/longobject.py
+++ b/pypy/objspace/std/longobject.py
@@ -78,7 +78,7 @@
         return space.newint(_hash_long(space, self.asbigint()))
 
     def descr_str(self, space):
-        return space.wrap(self.asbigint().str())
+        return space.newtext(self.asbigint().str())
     descr_repr = descr_str
 
 
diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -226,9 +226,8 @@
                 w_arg = space.getitem(self.w_kwargs, w_kwarg)
             else:
                 if self.args is None:
-                    w_msg = space.wrap("Format string contains positional "
-                                       "fields")
-                    raise OperationError(space.w_ValueError, w_msg)
+                    raise oefmt(space.w_ValueError,
+                                "Format string contains positional fields")
                 try:
                     w_arg = self.args[index]
                 except IndexError:
diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -147,7 +147,7 @@
             raise oefmt(space.w_IndexError, self._KIND1 + " index out of range")
         from pypy.objspace.std.bytesobject import W_BytesObject
         if isinstance(self, W_BytesObject):
-            return space.wrap(ord(character))
+            return space.newint(ord(character))
         return self._new(character)
 
     def descr_capitalize(self, space):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -751,7 +751,7 @@
             continue
         msg = ("metaclass conflict: the metaclass of a derived class must be "
                "a (non-strict) subclass of the metaclasses of all its bases")
-        raise OperationError(space.w_TypeError, space.wrap(msg))
+        raise oefmt(space.w_TypeError, msg)
     return w_winner
 
 def _precheck_for_new(space, w_type):
@@ -796,7 +796,7 @@
 
 def descr_get__qualname__(space, w_type):
     w_type = _check(space, w_type)
-    return space.wrap(w_type.getqualname(space))
+    return space.newunicode(w_type.getqualname(space))
 
 def descr_set__qualname__(space, w_type, w_value):
     w_type = _check(space, w_type)


More information about the pypy-commit mailing list