Author: Carl Friedrich Bolz <[email protected]>
Branch: space-newtext
Changeset: r88042:1bddaf521a03
Date: 2016-11-01 18:11 +0100
http://bitbucket.org/pypy/pypy/changeset/1bddaf521a03/

Log:    remove wrap calls from the __builtin__ module

diff --git a/pypy/module/__builtin__/__init__.py 
b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -101,7 +101,7 @@
         # this is obscure and slow
         space = self.space
         try:
-            w_builtin = space.getitem(w_globals, space.wrap('__builtins__'))
+            w_builtin = space.getitem(w_globals, space.newtext('__builtins__'))
         except OperationError as e:
             if not e.match(space, space.w_KeyError):
                 raise
@@ -114,7 +114,7 @@
                 return w_builtin
         # no builtin! make a default one.  Give them None, at least.
         builtin = module.Module(space, None)
-        space.setitem(builtin.w_dict, space.wrap('None'), space.w_None)
+        space.setitem(builtin.w_dict, space.newtext('None'), space.w_None)
         return builtin
 
     def setup_after_space_initialization(self):
diff --git a/pypy/module/__builtin__/abstractinst.py 
b/pypy/module/__builtin__/abstractinst.py
--- a/pypy/module/__builtin__/abstractinst.py
+++ b/pypy/module/__builtin__/abstractinst.py
@@ -20,7 +20,7 @@
     no __bases__ or if cls.__bases__ is not a tuple.
     """
     try:
-        w_bases = space.getattr(w_cls, space.wrap('__bases__'))
+        w_bases = space.getattr(w_cls, space.newtext('__bases__'))
     except OperationError as e:
         if not e.match(space, space.w_AttributeError):
             raise       # propagate other errors
@@ -35,12 +35,12 @@
 
 def check_class(space, w_obj, msg):
     if not abstract_isclass_w(space, w_obj):
-        raise OperationError(space.w_TypeError, space.wrap(msg))
+        raise OperationError(space.w_TypeError, space.newtext(msg))
 
 
 def abstract_getclass(space, w_obj):
     try:
-        return space.getattr(w_obj, space.wrap('__class__'))
+        return space.getattr(w_obj, space.newtext('__class__'))
     except OperationError as e:
         if not e.match(space, space.w_AttributeError):
             raise       # propagate other errors
@@ -62,7 +62,7 @@
     check_class(space, w_cls, "isinstance() arg 2 must be a class, type,"
                               " or tuple of classes and types")
     try:
-        w_abstractclass = space.getattr(w_inst, space.wrap('__class__'))
+        w_abstractclass = space.getattr(w_inst, space.newtext('__class__'))
     except OperationError as e:
         if e.async(space):      # ignore most exceptions
             raise
@@ -77,7 +77,7 @@
     if space.isinstance_w(w_inst, w_type):
         return True
     try:
-        w_abstractclass = space.getattr(w_inst, space.wrap('__class__'))
+        w_abstractclass = space.getattr(w_inst, space.newtext('__class__'))
     except OperationError as e:
         if e.async(space):      # ignore most exceptions
             raise
@@ -235,14 +235,14 @@
 another class.  When using a tuple as the second argument, check whether
 'cls' is a subclass of any of the classes listed in the tuple."""
     result = abstract_issubclass_w(space, w_cls, w_klass_or_tuple, True)
-    return space.wrap(result)
+    return space.newbool(result)
 
 def isinstance(space, w_obj, w_klass_or_tuple):
     """Check whether an object is an instance of a class (or of a subclass
 thereof).  When using a tuple as the second argument, check whether 'obj'
 is an instance of any of the classes listed in the tuple."""
     result = abstract_isinstance_w(space, w_obj, w_klass_or_tuple, True)
-    return space.wrap(result)
+    return space.newbool(result)
 
 # avoid namespace pollution
 app_issubclass = issubclass; del issubclass
diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -39,12 +39,11 @@
 
     if space.isinstance_w(w_source, space.gettypeobject(ast.W_AST.typedef)):
         ast_node = ast.mod.from_object(space, w_source)
-        code = ec.compiler.compile_ast(ast_node, filename, mode, flags)
-        return space.wrap(code)
+        return ec.compiler.compile_ast(ast_node, filename, mode, flags)
 
     if space.isinstance_w(w_source, space.w_unicode):
         w_utf_8_source = space.call_method(w_source, "encode",
-                                           space.wrap("utf-8"))
+                                           space.newtext("utf-8"))
         source = space.str_w(w_utf_8_source)
         # This flag tells the parser to reject any coding cookies it sees.
         flags |= consts.PyCF_SOURCE_IS_UTF8
@@ -60,8 +59,7 @@
         node = ec.compiler.compile_to_ast(source, filename, mode, flags)
         return node.to_object(space)
     else:
-        code = ec.compiler.compile(source, filename, mode, flags)
-        return space.wrap(code)
+        return ec.compiler.compile(source, filename, mode, flags)
 
 
 def eval(space, w_code, w_globals=None, w_locals=None):
@@ -75,7 +73,7 @@
         space.isinstance_w(w_code, space.w_unicode)):
         w_code = compile(space,
                          space.call_method(w_code, 'lstrip',
-                                           space.wrap(' \t')),
+                                           space.newtext(' \t')),
                          "<string>", "eval")
 
     if not isinstance(w_code, PyCode):
diff --git a/pypy/module/__builtin__/descriptor.py 
b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -28,7 +28,7 @@
             objtype_name = "<%s object>" % self.w_objtype.getname(space)
         else:
             objtype_name = 'NULL'
-        return space.wrap("<super: <class '%s'>, %s>" % (
+        return space.newtext("<super: <class '%s'>, %s>" % (
             self.w_starttype.getname(space), objtype_name))
 
     def get(self, space, w_obj, w_type=None):
@@ -77,7 +77,7 @@
         return w_objtype
 
     try:
-        w_type = space.getattr(w_obj_or_type, space.wrap('__class__'))
+        w_type = space.getattr(w_obj_or_type, space.newtext('__class__'))
     except OperationError as e:
         if not e.match(space, space.w_AttributeError):
             raise
@@ -130,12 +130,12 @@
         # our __doc__ comes from the getter if we don't have an explicit one
         if (space.is_w(self.w_doc, space.w_None) and
             not space.is_w(self.w_fget, space.w_None)):
-            w_getter_doc = space.findattr(self.w_fget, space.wrap('__doc__'))
+            w_getter_doc = space.findattr(self.w_fget, 
space.newtext('__doc__'))
             if w_getter_doc is not None:
                 if type(self) is W_Property:
                     self.w_doc = w_getter_doc
                 else:
-                    space.setattr(self, space.wrap('__doc__'), w_getter_doc)
+                    space.setattr(self, space.newtext('__doc__'), w_getter_doc)
                 self.getter_doc = True
 
     def get(self, space, w_obj, w_objtype=None):
diff --git a/pypy/module/__builtin__/functional.py 
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -54,7 +54,7 @@
 get a list in decending order."""
 
     if w_y is None:
-        w_start = space.wrap(0)
+        w_start = space.newint(0)
         w_stop = w_x
     else:
         w_start = w_x
@@ -91,7 +91,7 @@
     res_w = [None] * howmany
     v = start
     for idx in range(howmany):
-        res_w[idx] = space.wrap(v)
+        res_w[idx] = space.newint(v)
         v += step
     return space.newlist(res_w)
 
@@ -264,10 +264,10 @@
 
         self = space.allocate_instance(W_Enumerate, w_subtype)
         self.__init__(w_iter, start, w_start)
-        return space.wrap(self)
+        return self
 
     def descr___iter__(self, space):
-        return space.wrap(self)
+        return self
 
     def descr_next(self, space):
         from pypy.objspace.std.listobject import W_ListObject
@@ -289,14 +289,14 @@
                 try:
                     newval = rarithmetic.ovfcheck(index + 1)
                 except OverflowError:
-                    w_index = space.wrap(index)
-                    self.w_index = space.add(w_index, space.wrap(1))
+                    w_index = space.newint(index)
+                    self.w_index = space.add(w_index, space.newint(1))
                     self.index = -1
                 else:
                     self.index = newval
-            w_index = space.wrap(index)
+            w_index = space.newint(index)
         else:
-            self.w_index = space.add(w_index, space.wrap(1))
+            self.w_index = space.add(w_index, space.newint(1))
         if w_item is None:
             w_item = space.next(self.w_iter_or_list)
         return space.newtuple([w_index, w_item])
@@ -308,7 +308,7 @@
         w_new_inst = mod.get('enumerate_new')
         w_index = self.w_index
         if w_index is None:
-            w_index = space.wrap(self.index)
+            w_index = space.newint(self.index)
         w_info = space.newtuple([self.w_iter_or_list, w_index])
         return space.newtuple([w_new_inst, w_info])
 
@@ -319,7 +319,7 @@
         w_index = None
     else:
         index = -1
-    return space.wrap(W_Enumerate(w_iter_or_list, index, w_index))
+    return W_Enumerate(w_iter_or_list, index, w_index)
 
 W_Enumerate.typedef = TypeDef("enumerate",
     __new__=interp2app(W_Enumerate.descr___new__.im_func),
@@ -333,14 +333,14 @@
     """Return a iterator that yields items of sequence in reverse."""
     w_reversed = None
     if space.is_oldstyle_instance(w_sequence):
-        w_reversed = space.findattr(w_sequence, space.wrap("__reversed__"))
+        w_reversed = space.findattr(w_sequence, space.newtext("__reversed__"))
     else:
         w_reversed_descr = space.lookup(w_sequence, "__reversed__")
         if w_reversed_descr is not None:
             w_reversed = space.get(w_reversed_descr, w_sequence)
     if w_reversed is not None:
         return space.call_function(w_reversed)
-    return space.wrap(W_ReversedIterator(space, w_sequence))
+    return W_ReversedIterator(space, w_sequence)
 
 
 class W_ReversedIterator(W_Root):
@@ -352,14 +352,14 @@
         self.w_sequence = w_sequence
 
     def descr___iter__(self, space):
-        return space.wrap(self)
+        return self
 
     def descr_length(self, space):
-        return space.wrap(0 if self.remaining == -1 else self.remaining + 1)
+        return space.newint(0 if self.remaining == -1 else self.remaining + 1)
 
     def descr_next(self, space):
         if self.remaining >= 0:
-            w_index = space.wrap(self.remaining)
+            w_index = space.newint(self.remaining)
             try:
                 w_item = space.getitem(self.w_sequence, w_index)
             except OperationError as e:
@@ -385,7 +385,7 @@
         mod      = space.interp_w(MixedModule, w_mod)
         w_new_inst = mod.get('reversed_new')
         w_seq = space.w_None if self.w_sequence is None else self.w_sequence
-        info_w = [w_seq, space.wrap(self.remaining)]
+        info_w = [w_seq, space.newint(self.remaining)]
         w_info = space.newtuple(info_w)
         return space.newtuple([w_new_inst, w_info])
 
@@ -407,7 +407,7 @@
     else:
         iterator.w_sequence = w_seq
         iterator.remaining = space.int_w(w_remaining)
-    return space.wrap(iterator)
+    return iterator
 
 
 class W_XRange(W_Root):
@@ -431,9 +431,9 @@
         else:
             stop = space.int_w(w_stop)
         howmany = get_len_of_range(space, start, stop, step)
-        obj = space.allocate_instance(W_XRange, w_subtype)
-        W_XRange.__init__(obj, space, start, howmany, step, promote_step)
-        return space.wrap(obj)
+        w_obj = space.allocate_instance(W_XRange, w_subtype)
+        W_XRange.__init__(w_obj, space, start, howmany, step, promote_step)
+        return w_obj
 
     def descr_repr(self):
         if self.start == 0 and self.step == 1:
@@ -442,10 +442,10 @@
             s = "xrange(%d, %d)" % (self.start, self._get_stop())
         else:
             s = "xrange(%d, %d, %d)" %(self.start, self._get_stop(), self.step)
-        return self.space.wrap(s)
+        return self.space.newtext(s)
 
     def descr_len(self):
-        return self.space.wrap(self.len)
+        return self.space.newint(self.len)
 
     @unwrap_spec(i='index')
     def descr_getitem(self, i):
@@ -455,31 +455,31 @@
         if i < 0:
             i += len
         if 0 <= i < len:
-            return space.wrap(self.start + i * self.step)
+            return space.newint(self.start + i * self.step)
         raise oefmt(space.w_IndexError, "xrange object index out of range")
 
     def descr_iter(self):
         if self.promote_step and self.step == 1:
             stop = self.start + self.len
-            return self.space.wrap(W_XRangeStepOneIterator(self.space,
-                                                           self.start,
-                                                           stop))
+            return W_XRangeStepOneIterator(self.space,
+                                           self.start,
+                                           stop)
         else:
-            return self.space.wrap(W_XRangeIterator(self.space, self.start,
-                                                    self.len, self.step))
+            return W_XRangeIterator(self.space, self.start,
+                                    self.len, self.step)
 
     def descr_reversed(self):
         last = self.start + (self.len - 1) * self.step
-        return self.space.wrap(W_XRangeIterator(self.space, last, self.len,
-                                                -self.step))
+        return W_XRangeIterator(self.space, last, self.len,
+                                -self.step)
 
     def descr_reduce(self):
         space = self.space
         return space.newtuple(
             [space.type(self),
-             space.newtuple([space.wrap(self.start),
-                             space.wrap(self._get_stop()),
-                             space.wrap(self.step)])
+             space.newtuple([space.newint(self.start),
+                             space.newint(self._get_stop()),
+                             space.newint(self.step)])
              ])
 
     def _get_stop(self):
@@ -512,7 +512,7 @@
         self.step = step
 
     def descr_iter(self):
-        return self.space.wrap(self)
+        return self
 
     def descr_next(self):
         return self.next()
@@ -522,11 +522,11 @@
             item = self.current
             self.current = item + self.step
             self.remaining -= 1
-            return self.space.wrap(item)
+            return self.space.newint(item)
         raise OperationError(self.space.w_StopIteration, self.space.w_None)
 
     def descr_len(self):
-        return self.space.wrap(self.get_remaining())
+        return self.space.newint(self.get_remaining())
 
     def descr_reduce(self):
         from pypy.interpreter.mixedmodule import MixedModule
@@ -534,10 +534,9 @@
         w_mod    = space.getbuiltinmodule('_pickle_support')
         mod      = space.interp_w(MixedModule, w_mod)
         new_inst = mod.get('xrangeiter_new')
-        w        = space.wrap
         nt = space.newtuple
 
-        tup = [w(self.current), w(self.get_remaining()), w(self.step)]
+        tup = [space.newint(self.current), space.newint(self.get_remaining()), 
space.newint(self.step)]
         return nt([new_inst, nt(tup)])
 
     def get_remaining(self):
@@ -565,7 +564,7 @@
         if self.current < self.stop:
             item = self.current
             self.current = item + 1
-            return self.space.wrap(item)
+            return self.space.newint(item)
         raise OperationError(self.space.w_StopIteration, self.space.w_None)
 
     def get_remaining(self):
diff --git a/pypy/module/__builtin__/interp_classobj.py 
b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -21,8 +21,8 @@
     if not space.isinstance_w(w_dict, space.w_dict):
         raise_type_err(space, 'bases', 'tuple', w_bases)
 
-    if not space.contains_w(w_dict, space.wrap("__doc__")):
-        space.setitem(w_dict, space.wrap("__doc__"), space.w_None)
+    if not space.contains_w(w_dict, space.newtext("__doc__")):
+        space.setitem(w_dict, space.newtext("__doc__"), space.w_None)
 
     # XXX missing: lengthy and obscure logic about "__module__"
 
@@ -109,7 +109,7 @@
             if name == "__dict__":
                 return self.w_dict
             elif name == "__name__":
-                return space.wrap(self.name)
+                return space.newtext(self.name)
             elif name == "__bases__":
                 return space.newtuple(self.bases_w)
         w_value = self.lookup(space, name)
@@ -138,7 +138,7 @@
                 if not self.has_user_del(space):
                     msg = ("a __del__ method added to an existing class will "
                            "only be called on instances made from now on")
-                    space.warn(space.wrap(msg), space.w_RuntimeWarning)
+                    space.warn(space.newtext(msg), space.w_RuntimeWarning)
         space.setitem(self.w_dict, w_attr, w_value)
 
     def descr_delattr(self, space, w_attr):
@@ -161,9 +161,9 @@
     def descr_str(self, space):
         mod = self.get_module_string(space)
         if mod == "?":
-            return space.wrap(self.name)
+            return space.newtext(self.name)
         else:
-            return space.wrap("%s.%s" % (mod, self.name))
+            return space.newtext("%s.%s" % (mod, self.name))
 
     def get_module_string(self, space):
         try:
@@ -338,7 +338,7 @@
         w_meth = self.getattr_from_class(space, '__getattr__')
         if w_meth is not None:
             try:
-                return space.call_function(w_meth, space.wrap(name))
+                return space.call_function(w_meth, space.newtext(name))
             except OperationError as e:
                 if not exc and e.match(space, space.w_AttributeError):
                     return None     # eat the AttributeError
@@ -375,7 +375,7 @@
                     and self.getdictvalue(space, '__del__') is None):
                     msg = ("a __del__ method added to an instance with no "
                            "__del__ in the class will not be called")
-                    space.warn(space.wrap(msg), space.w_RuntimeWarning)
+                    space.warn(space.newtext(msg), space.w_RuntimeWarning)
         if w_meth is not None:
             space.call_function(w_meth, w_name, w_value)
         else:
@@ -433,14 +433,14 @@
             if space.len_w(w_format_spec) > 0:
                 msg = ("object.__format__ with a non-empty format string is "
                        "deprecated")
-                space.warn(space.wrap(msg), space.w_PendingDeprecationWarning)
+                space.warn(space.newtext(msg), 
space.w_PendingDeprecationWarning)
             return space.format(w_as_str, w_format_spec)
 
     def descr_len(self, space):
         w_meth = self.getattr(space, '__len__')
         w_result = space.call_function(w_meth)
         if space.isinstance_w(w_result, space.w_int):
-            if space.is_true(space.lt(w_result, space.wrap(0))):
+            if space.is_true(space.lt(w_result, space.newint(0))):
                 raise oefmt(space.w_ValueError, "__len__() should return >= 0")
             return w_result
         raise oefmt(space.w_TypeError, "__len__() should return an int")
@@ -502,7 +502,7 @@
                 return space.w_True
         w_result = space.call_function(w_func)
         if space.isinstance_w(w_result, space.w_int):
-            if space.is_true(space.lt(w_result, space.wrap(0))):
+            if space.is_true(space.lt(w_result, space.newint(0))):
                 raise oefmt(space.w_ValueError,
                             "__nonzero__() should return >= 0")
             return w_result
@@ -527,10 +527,10 @@
                                     "__cmp__ must return int")
                     raise
                 if res > 0:
-                    return space.wrap(1)
+                    return space.newint(1)
                 if res < 0:
-                    return space.wrap(-1)
-                return space.wrap(0)
+                    return space.newint(-1)
+                return space.newint(0)
         if isinstance(w_b, W_InstanceObject):
             w_func = w_b.getattr(space, '__cmp__', False)
             if w_func is not None:
@@ -545,10 +545,10 @@
                                     "__cmp__ must return int")
                     raise
                 if res < 0:
-                    return space.wrap(1)
+                    return space.newint(1)
                 if res > 0:
-                    return space.wrap(-1)
-                return space.wrap(0)
+                    return space.newint(-1)
+                return space.newint(0)
         return space.w_NotImplemented
 
     def descr_hash(self, space):
@@ -559,7 +559,7 @@
             if w_eq is not None or w_cmp is not None:
                 raise oefmt(space.w_TypeError, "unhashable instance")
             else:
-                return space.wrap(compute_identity_hash(self))
+                return space.newint(compute_identity_hash(self))
         w_ret = space.call_function(w_func)
         if (not space.isinstance_w(w_ret, space.w_int) and
             not space.isinstance_w(w_ret, space.w_long)):
@@ -598,7 +598,7 @@
     def descr_contains(self, space, w_obj):
         w_func = self.getattr(space, '__contains__', False)
         if w_func is not None:
-            return space.wrap(space.is_true(space.call_function(w_func, 
w_obj)))
+            return space.newbool(space.is_true(space.call_function(w_func, 
w_obj)))
         # now do it ourselves
         w_iter = space.iter(self)
         while 1:
diff --git a/pypy/module/__builtin__/operation.py 
b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -30,7 +30,7 @@
         c = UNICHR(code)
     except ValueError:
         raise oefmt(space.w_ValueError, "unichr() arg out of range")
-    return space.wrap(c)
+    return space.newunicode(c)
 
 def len(space, w_obj):
     "len(object) -> integer\n\nReturn the number of items of a sequence or 
mapping."
@@ -46,7 +46,7 @@
     # unmodified (and not e.g. unwrapped-rewrapped).
     if not space.is_w(space.type(w_name), space.w_str):
         name = space.str_w(w_name)    # typecheck
-        w_name = space.wrap(name)     # rewrap as a real string
+        w_name = space.newtext(name)     # rewrap as a real string
     return w_name
 
 def delattr(space, w_object, w_name):
@@ -135,23 +135,23 @@
 
     # nans, infinities and zeros round to themselves
     if number == 0 or isinf(number) or isnan(number):
-        return space.wrap(number)
+        return space.newfloat(number)
 
     # Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x
     # always rounds to itself.  For ndigits < NDIGITS_MIN, x always
     # rounds to +-0.0.
     if ndigits > NDIGITS_MAX:
-        return space.wrap(number)
+        return space.newfloat(number)
     elif ndigits < NDIGITS_MIN:
         # return 0.0, but with sign of x
-        return space.wrap(0.0 * number)
+        return space.newfloat(0.0 * number)
 
     # finite x, and ndigits is not unreasonably large
     z = round_double(number, ndigits)
     if isinf(z):
         raise oefmt(space.w_OverflowError,
                     "rounded value too large to represent")
-    return space.wrap(z)
+    return space.newfloat(z)
 
 # ____________________________________________________________
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to