[pypy-commit] pypy space-newtext: start on the wraps in interpreter/
cfbolz
pypy.commits at gmail.com
Thu Oct 20 12:50:57 EDT 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: space-newtext
Changeset: r87901:2601d8768d87
Date: 2016-10-20 18:50 +0200
http://bitbucket.org/pypy/pypy/changeset/2601d8768d87/
Log: start on the wraps in interpreter/
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -159,7 +159,7 @@
space.setitem(w_globals, space.newtext('__builtins__'),
space.builtin_modules['__builtin__'])
space.setitem(w_globals, space.newtext('c_argument'),
- space.newtext(c_argument))
+ space.newint(c_argument))
space.appexec([space.newtext(source), w_globals], """(src, glob):
import sys
stmt = compile(src, 'c callback', 'exec')
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -534,8 +534,8 @@
except IndexError:
name = '?'
else:
- w_enc = space.wrap(space.sys.defaultencoding)
- w_err = space.wrap("replace")
+ w_enc = space.newtext(space.sys.defaultencoding)
+ w_err = space.newtext("replace")
w_name = space.call_method(w_name, "encode", w_enc,
w_err)
name = space.str_w(w_name)
diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -438,7 +438,7 @@
self.fields = fields
def __spacebind__(self, space):
- return space.newtuple([space.wrap(field) for field in self.fields])
+ return space.newtuple([space.newtext(field) for field in self.fields])
class W_AST(W_Root):
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -51,7 +51,7 @@
w_dict = self.getdict(space)
if w_dict is not None:
try:
- space.delitem(w_dict, space.wrap(attr))
+ space.delitem(w_dict, space.newtext(attr))
return True
except OperationError as ex:
if not ex.match(space, space.w_KeyError):
@@ -77,7 +77,7 @@
def getname(self, space):
try:
- return space.str_w(space.getattr(self, space.wrap('__name__')))
+ return space.str_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 '?'
@@ -104,8 +104,8 @@
def getrepr(self, space, info, moreinfo=''):
addrstring = self.getaddrstring(space)
- return space.wrap("<%s at 0x%s%s>" % (info, addrstring,
- moreinfo))
+ return space.newtext("<%s at 0x%s%s>" % (info, addrstring,
+ moreinfo))
def getslotvalue(self, index):
raise NotImplementedError
@@ -1848,7 +1848,7 @@
source = py.code.Source("def anonymous%s\n" % source)
w_glob = space.newdict(module=True)
space.exec_(str(source), w_glob, w_glob)
- return space.getitem(w_glob, space.wrap('anonymous'))
+ return space.getitem(w_glob, space.newtext('anonymous'))
# Table describing the regular part of the interface of object spaces,
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -72,12 +72,11 @@
exc_typename = str(self.w_type)
exc_value = str(w_value)
else:
- w = space.wrap
if space.is_w(space.type(self.w_type), space.w_str):
exc_typename = space.str_w(self.w_type)
else:
exc_typename = space.str_w(
- space.getattr(self.w_type, w('__name__')))
+ space.getattr(self.w_type, space.newtext('__name__')))
if space.is_w(w_value, space.w_None):
exc_value = ""
else:
@@ -187,7 +186,7 @@
w_type = self.w_type
w_value = self.get_w_value(space)
while space.isinstance_w(w_type, space.w_tuple):
- w_type = space.getitem(w_type, space.wrap(0))
+ w_type = space.getitem(w_type, space.newint(0))
if space.exception_is_valid_obj_as_class_w(w_type):
# this is for all cases of the form (Class, something)
diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -8,8 +8,8 @@
def app_profile_call(space, w_callable, frame, event, w_arg):
space.call_function(w_callable,
- space.wrap(frame),
- space.wrap(event), w_arg)
+ frame,
+ space.newtext(event), w_arg)
class ExecutionContext(object):
"""An ExecutionContext holds the state of an execution thread
@@ -323,7 +323,7 @@
if operr is not None:
w_value = operr.get_w_value(space)
w_arg = space.newtuple([operr.w_type, w_value,
- space.wrap(operr.get_traceback())])
+ operr.get_traceback()])
d = frame.getorcreatedebug()
if d.w_locals is not None:
@@ -334,7 +334,7 @@
self.is_tracing += 1
try:
try:
- w_result = space.call_function(w_callback, space.wrap(frame), space.wrap(event), w_arg)
+ w_result = space.call_function(w_callback, frame, space.newtext(event), w_arg)
if space.is_w(w_result, space.w_None):
d.w_f_trace = None
else:
@@ -605,7 +605,7 @@
msg = ("RPython exception %s in %s<%s at 0x%s> ignored\n" % (
str(e), where, space.type(w_obj).name, addrstring))
space.call_method(space.sys.get('stderr'), 'write',
- space.wrap(msg))
+ space.newtext(msg))
def make_finalizer_queue(W_Root, space):
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -239,7 +239,7 @@
closure = [space.interp_w(Cell, w_cell) for w_cell in closure_w]
func = space.allocate_instance(Function, w_subtype)
Function.__init__(func, space, code, w_globals, defs_w, closure, name)
- return space.wrap(func)
+ return func
def descr_function_call(self, __args__):
return self.call_args(__args__)
@@ -279,14 +279,13 @@
if isinstance(code, BuiltinCode):
new_inst = mod.get('builtin_function')
return space.newtuple([new_inst,
- space.newtuple([space.wrap(code.identifier)])])
+ space.newtuple([space.newtext(code.identifier)])])
new_inst = mod.get('func_new')
- w = space.wrap
if self.closure is None:
w_closure = space.w_None
else:
- w_closure = space.newtuple([w(cell) for cell in self.closure])
+ w_closure = space.newtuple([cell for cell in self.closure])
if self.w_doc is None:
w_doc = space.w_None
else:
@@ -303,9 +302,9 @@
nt = space.newtuple
tup_base = []
tup_state = [
- w(self.name),
+ space.newtext(self.name),
w_doc,
- w(self.code),
+ self.code,
w_func_globals,
w_closure,
nt(self.defs_w),
@@ -325,7 +324,7 @@
"Wrong arguments to function.__setstate__")
self.space = space
- self.name = space.str_w(w_name)
+ self.name = space.text_w(w_name)
self.code = space.interp_w(Code, w_code)
if not space.is_w(w_closure, space.w_None):
from pypy.interpreter.nestedscope import Cell
@@ -375,7 +374,7 @@
self.w_doc = w_doc
def fget_func_name(self, space):
- return space.wrap(self.name)
+ return space.newtext(self.name)
def fset_func_name(self, space, w_name):
if space.isinstance_w(w_name, space.w_str):
@@ -390,7 +389,7 @@
def fget___module__(self, space):
if self.w_module is None:
if self.w_func_globals is not None and not space.is_w(self.w_func_globals, space.w_None):
- self.w_module = space.call_method(self.w_func_globals, "get", space.wrap("__name__"))
+ self.w_module = space.call_method(self.w_func_globals, "get", space.newtext("__name__"))
else:
self.w_module = space.w_None
return self.w_module
@@ -402,7 +401,7 @@
self.w_module = space.w_None
def fget_func_code(self, space):
- return space.wrap(self.code)
+ return self.code
def fset_func_code(self, space, w_code):
from pypy.interpreter.pycode import PyCode
@@ -422,7 +421,7 @@
def fget_func_closure(self, space):
if self.closure is not None:
- w_res = space.newtuple([space.wrap(i) for i in self.closure])
+ w_res = space.newtuple([cell for cell in self.closure])
else:
w_res = space.w_None
return w_res
@@ -436,9 +435,9 @@
not space.is_w(w_obj, space.w_None) or
space.is_w(w_cls, space.type(space.w_None)))
if asking_for_bound:
- return space.wrap(Method(space, w_function, w_obj, w_cls))
+ return Method(space, w_function, w_obj, w_cls)
else:
- return space.wrap(Method(space, w_function, None, w_cls))
+ return Method(space, w_function, None, w_cls)
class Method(W_Root):
@@ -461,7 +460,7 @@
raise oefmt(space.w_TypeError, "unbound methods must have class")
method = space.allocate_instance(Method, w_subtype)
Method.__init__(method, space, w_function, w_instance, w_class)
- return space.wrap(method)
+ return method
def __repr__(self):
if self.w_instance:
@@ -503,14 +502,14 @@
def descr_method_get(self, w_obj, w_cls=None):
space = self.space
if self.w_instance is not None:
- return space.wrap(self) # already bound
+ return self # already bound
else:
# only allow binding to a more specific class than before
if (w_cls is not None and
not space.is_w(w_cls, space.w_None) and
not space.abstract_issubclass_w(w_cls, self.w_class,
allow_override=True)):
- return space.wrap(self) # subclass test failed
+ return self # subclass test failed
else:
return descr_function_get(space, self.w_function, w_obj, w_cls)
@@ -528,18 +527,18 @@
typename = w_class.getname(self.space)
if self.w_instance is None:
s = "<unbound method %s.%s>" % (typename, name)
- return space.wrap(s)
+ return space.newtext(s)
else:
objrepr = space.str_w(space.repr(self.w_instance))
s = '<bound method %s.%s of %s>' % (typename, name, objrepr)
- return space.wrap(s)
+ return space.newtext(s)
def descr_method_getattribute(self, w_attr):
space = self.space
if space.str_w(w_attr) != '__doc__':
try:
return space.call_method(space.w_object, '__getattribute__',
- space.wrap(self), w_attr)
+ self, w_attr)
except OperationError as e:
if not e.match(space, space.w_AttributeError):
raise
@@ -599,9 +598,9 @@
isinstance(w_function.code, BuiltinCode)):
new_inst = mod.get('builtin_method_new')
if space.is_w(w_instance, space.w_None):
- tup = [self.w_class, space.wrap(w_function.name)]
+ tup = [self.w_class, space.newtext(w_function.name)]
else:
- tup = [w_instance, space.wrap(w_function.name)]
+ tup = [w_instance, space.newtext(w_function.name)]
elif space.is_w(self.w_class, space.w_None):
tup = [self.w_function, w_instance]
else:
@@ -623,7 +622,7 @@
def descr_staticmethod__new__(space, w_subtype, w_function):
instance = space.allocate_instance(StaticMethod, w_subtype)
instance.__init__(w_function)
- return space.wrap(instance)
+ return instance
class ClassMethod(W_Root):
@@ -636,13 +635,13 @@
def descr_classmethod_get(self, space, w_obj, w_klass=None):
if space.is_none(w_klass):
w_klass = space.type(w_obj)
- return space.wrap(Method(space, self.w_function, w_klass,
- space.type(w_klass)))
+ return Method(space, self.w_function, w_klass,
+ space.type(w_klass))
def descr_classmethod__new__(space, w_subtype, w_function):
instance = space.allocate_instance(ClassMethod, w_subtype)
instance.__init__(w_function)
- return space.wrap(instance)
+ return instance
class FunctionWithFixedCode(Function):
can_change_code = False
@@ -663,7 +662,7 @@
"cannot create 'builtin_function' instances")
def descr_function_repr(self):
- return self.space.wrap('<built-in function %s>' % (self.name,))
+ return self.space.newtext('<built-in function %s>' % (self.name,))
def is_builtin_code(w_func):
from pypy.interpreter.gateway import BuiltinCode
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -670,7 +670,7 @@
mod = space.interp_w(MixedModule, w_mod)
builtin_code = mod.get('builtin_code')
return space.newtuple([builtin_code,
- space.newtuple([space.wrap(self.identifier)])])
+ space.newtuple([space.newtext(self.identifier)])])
def find(indentifier):
from pypy.interpreter.function import Function
@@ -681,7 +681,7 @@
return self.sig
def getdocstring(self, space):
- return space.wrap(self.docstring)
+ return space.newtext(self.docstring)
def funcrun(self, func, args):
return BuiltinCode.funcrun_obj(self, func, None, args)
@@ -1062,11 +1062,11 @@
def buildmodule(self, space, name='applevel'):
from pypy.interpreter.module import Module
- return Module(space, space.wrap(name), self.getwdict(space))
+ return Module(space, space.newtext(name), self.getwdict(space))
def wget(self, space, name):
w_globals = self.getwdict(space)
- return space.getitem(w_globals, space.wrap(name))
+ return space.getitem(w_globals, space.newtext(name))
def interphook(self, name):
"NOT_RPYTHON"
@@ -1116,7 +1116,7 @@
def build_applevel_dict(self, space):
"NOT_RPYTHON"
w_glob = space.newdict(module=True)
- space.setitem(w_glob, space.wrap('__name__'), space.wrap(self.modname))
+ space.setitem(w_glob, space.newtext('__name__'), space.newtext(self.modname))
space.exec_(self.source, w_glob, w_glob,
hidden_applevel=self.hidden_applevel,
filename=self.filename)
diff --git a/pypy/interpreter/interactive.py b/pypy/interpreter/interactive.py
--- a/pypy/interpreter/interactive.py
+++ b/pypy/interpreter/interactive.py
@@ -93,13 +93,13 @@
mainmodule = main.ensure__main__(space)
self.w_globals = mainmodule.w_dict
- space.setitem(self.w_globals, space.wrap('__builtins__'), space.builtin)
+ space.setitem(self.w_globals, space.newtext('__builtins__'), space.builtin)
if completer:
self.enable_command_line_completer()
# forbidden:
#space.exec_("__pytrace__ = 0", self.w_globals, self.w_globals)
- space.setitem(self.w_globals, space.wrap('__pytrace__'),space.newint(0))
+ space.setitem(self.w_globals, space.newtext('__pytrace__'),space.newint(0))
self.tracelevel = 0
self.console_locals = {}
@@ -159,7 +159,7 @@
for name in local:
if name.startswith('w_'):
self.space.setitem(self.w_globals,
- self.space.wrap(name[2:]),
+ self.space.newtext(name[2:]),
local[name])
print '*** Leaving interpreter-level console ***'
raise
diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py
--- a/pypy/interpreter/main.py
+++ b/pypy/interpreter/main.py
@@ -4,7 +4,7 @@
def ensure__main__(space):
- w_main = space.wrap('__main__')
+ w_main = space.newtext('__main__')
w_modules = space.sys.get('modules')
try:
return space.getitem(w_modules, w_main)
@@ -17,9 +17,8 @@
def compilecode(space, source, filename, cmd='exec'):
- w = space.wrap
w_code = space.builtin.call(
- 'compile', w(source), w(filename), w(cmd), w(0), w(0))
+ 'compile', space.wrap(source), space.wrap(filename), space.wrap(cmd), space.newint(0), space.newint(0))
pycode = space.interp_w(eval.Code, w_code)
return pycode
@@ -35,16 +34,14 @@
from pypy.objspace.std import StdObjSpace
space = StdObjSpace()
- w = space.wrap
-
pycode = compilecode(space, source, filename or '<string>', cmd)
mainmodule = ensure__main__(space)
w_globals = mainmodule.w_dict
- space.setitem(w_globals, w('__builtins__'), space.builtin)
+ space.setitem(w_globals, space.newtext('__builtins__'), space.builtin)
if filename is not None:
- space.setitem(w_globals, w('__file__'), w(filename))
+ space.setitem(w_globals, space.newtext('__file__'), space.newtext(filename))
retval = pycode.exec_code(space, w_globals, w_globals)
if eval:
@@ -83,16 +80,15 @@
if space is None:
from pypy.objspace.std import StdObjSpace
space = StdObjSpace()
- w = space.wrap
argv = [module_name]
if args is not None:
argv.extend(args)
- space.setitem(space.sys.w_dict, w('argv'), w(argv))
+ space.setitem(space.sys.w_dict, space.newtext('argv'), space.wrap(argv))
w_import = space.builtin.get('__import__')
- runpy = space.call_function(w_import, w('runpy'))
- w_run_module = space.getitem(runpy.w_dict, w('run_module'))
- return space.call_function(w_run_module, w(module_name), space.w_None,
- w('__main__'), space.w_True)
+ runpy = space.call_function(w_import, space.wrap('runpy'))
+ w_run_module = space.getitem(runpy.w_dict, space.wrap('run_module'))
+ return space.call_function(w_run_module, space.wrap(module_name), space.w_None,
+ space.wrap('__main__'), space.w_True)
def run_toplevel(space, f, verbose=False):
@@ -109,14 +105,14 @@
# we arrive here if no exception is raised. stdout cosmetics...
try:
w_stdout = space.sys.get('stdout')
- w_softspace = space.getattr(w_stdout, space.wrap('softspace'))
+ w_softspace = space.getattr(w_stdout, space.newtext('softspace'))
except OperationError as e:
if not e.match(space, space.w_AttributeError):
raise
# Don't crash if user defined stdout doesn't have softspace
else:
if space.is_true(w_softspace):
- space.call_method(w_stdout, 'write', space.wrap('\n'))
+ space.call_method(w_stdout, 'write', space.newtext('\n'))
except OperationError as operationerr:
operationerr.normalize_exception(space)
@@ -133,7 +129,7 @@
# exit if we catch a w_SystemExit
if operationerr.match(space, space.w_SystemExit):
w_exitcode = space.getattr(w_value,
- space.wrap('code'))
+ space.newtext('code'))
if space.is_w(w_exitcode, space.w_None):
exitcode = 0
else:
@@ -147,9 +143,9 @@
raise SystemExit(exitcode)
# set the sys.last_xxx attributes
- space.setitem(space.sys.w_dict, space.wrap('last_type'), w_type)
- space.setitem(space.sys.w_dict, space.wrap('last_value'), w_value)
- space.setitem(space.sys.w_dict, space.wrap('last_traceback'),
+ space.setitem(space.sys.w_dict, space.newtext('last_type'), w_type)
+ space.setitem(space.sys.w_dict, space.newtext('last_value'), w_value)
+ space.setitem(space.sys.w_dict, space.newtext('last_traceback'),
w_traceback)
# call sys.excepthook if present
diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py
--- a/pypy/interpreter/mixedmodule.py
+++ b/pypy/interpreter/mixedmodule.py
@@ -33,7 +33,7 @@
for sub_name, module_cls in self.submodules.iteritems():
if module_cls.submodule_name is None:
module_cls.submodule_name = sub_name
- module_name = space.wrap("%s.%s" % (name, sub_name))
+ module_name = space.newtext("%s.%s" % (name, sub_name))
m = module_cls(space, module_name)
m.install()
self.submodules_w.append(m)
@@ -49,7 +49,7 @@
for w_submodule in self.submodules_w:
name = space.str0_w(w_submodule.w_name)
- space.setitem(self.w_dict, space.wrap(name.split(".")[-1]), w_submodule)
+ space.setitem(self.w_dict, space.newtext(name.split(".")[-1]), w_submodule)
space.getbuiltinmodule(name)
if self.w_initialdict is None:
@@ -73,7 +73,7 @@
space = self.space
w_value = self.getdictvalue(space, name)
if w_value is None:
- raise OperationError(space.w_AttributeError, space.wrap(name))
+ raise OperationError(space.w_AttributeError, space.newtext(name))
return w_value
def call(self, name, *args_w):
@@ -154,7 +154,7 @@
loader = getinterpevalloader(pkgroot, spec)
space = self.space
w_obj = loader(space)
- space.setattr(space.wrap(self), space.wrap(name), w_obj)
+ space.setattr(self, space.newtext(name), w_obj)
@classmethod
def get__doc__(cls, space):
diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -36,15 +36,14 @@
statically inside the executable."""
try:
space = self.space
- space.delitem(self.w_dict, space.wrap('__file__'))
+ space.delitem(self.w_dict, space.newtext('__file__'))
except OperationError:
pass
def install(self):
"""NOT_RPYTHON: installs this module into space.builtin_modules"""
- w_mod = self.space.wrap(self)
modulename = self.space.str0_w(self.w_name)
- self.space.builtin_modules[modulename] = w_mod
+ self.space.builtin_modules[modulename] = self
def setup_after_space_initialization(self):
"""NOT_RPYTHON: to allow built-in modules to do some more setup
diff --git a/pypy/interpreter/nestedscope.py b/pypy/interpreter/nestedscope.py
--- a/pypy/interpreter/nestedscope.py
+++ b/pypy/interpreter/nestedscope.py
@@ -54,7 +54,7 @@
space.newtuple(tup)])
def descr__setstate__(self, space, w_state):
- self.w_value = space.getitem(w_state, space.wrap(0))
+ self.w_value = space.getitem(w_state, space.newint(0))
def __repr__(self):
""" representation for debugging purposes """
@@ -72,7 +72,7 @@
content = "%s object at 0x%s" % (space.type(self.w_value).name,
self.w_value.getaddrstring(space))
s = "<cell at 0x%s: %s>" % (self.getaddrstring(space), content)
- return space.wrap(s)
+ return space.newtext(s)
def descr__cell_contents(self, space):
try:
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -309,13 +309,13 @@
return space.newtuple(self.co_names_w)
def fget_co_varnames(self, space):
- return space.newtuple([space.wrap(name) for name in self.co_varnames])
+ return space.newtuple([space.newtext(name) for name in self.co_varnames])
def fget_co_cellvars(self, space):
- return space.newtuple([space.wrap(name) for name in self.co_cellvars])
+ return space.newtuple([space.newtext(name) for name in self.co_cellvars])
def fget_co_freevars(self, space):
- return space.newtuple([space.wrap(name) for name in self.co_freevars])
+ return space.newtuple([space.newtext(name) for name in self.co_freevars])
def descr_code__eq__(self, w_other):
space = self.space
@@ -356,7 +356,7 @@
for name in self.co_varnames: result ^= compute_hash(name)
for name in self.co_freevars: result ^= compute_hash(name)
for name in self.co_cellvars: result ^= compute_hash(name)
- w_result = space.wrap(intmask(result))
+ w_result = space.newint(intmask(result))
for w_name in self.co_names_w:
w_result = space.xor(w_result, space.hash(w_name))
for w_const in self.co_consts_w:
@@ -395,30 +395,29 @@
code = space.allocate_instance(PyCode, w_subtype)
PyCode.__init__(code, space, argcount, nlocals, stacksize, flags, codestring, consts_w[:], names,
varnames, filename, name, firstlineno, lnotab, freevars, cellvars, magic=magic)
- return space.wrap(code)
+ return code
def descr__reduce__(self, space):
from pypy.interpreter.mixedmodule import MixedModule
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
new_inst = mod.get('code_new')
- w = space.wrap
tup = [
- w(self.co_argcount),
- w(self.co_nlocals),
- w(self.co_stacksize),
- w(self.co_flags),
+ space.newint(self.co_argcount),
+ space.newint(self.co_nlocals),
+ space.newint(self.co_stacksize),
+ space.newint(self.co_flags),
space.newbytes(self.co_code),
space.newtuple(self.co_consts_w),
space.newtuple(self.co_names_w),
- space.newtuple([w(v) for v in self.co_varnames]),
- w(self.co_filename),
- w(self.co_name),
- w(self.co_firstlineno),
+ space.newtuple([space.newtext(v) for v in self.co_varnames]),
+ space.newtext(self.co_filename),
+ space.newtext(self.co_name),
+ space.newint(self.co_firstlineno),
space.newbytes(self.co_lnotab),
- space.newtuple([w(v) for v in self.co_freevars]),
- space.newtuple([w(v) for v in self.co_cellvars]),
- w(self.magic),
+ space.newtuple([space.newtext(v) for v in self.co_freevars]),
+ space.newtuple([space.newtext(v) for v in self.co_cellvars]),
+ space.newint(self.magic),
]
return space.newtuple([new_inst, space.newtuple(tup)])
@@ -430,4 +429,4 @@
return self.get_repr()
def repr(self, space):
- return space.wrap(self.get_repr())
+ return space.newtext(self.get_repr())
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -242,7 +242,7 @@
"""Start this frame's execution."""
if self.getcode().co_flags & pycode.CO_GENERATOR:
from pypy.interpreter.generator import GeneratorIterator
- return self.space.wrap(GeneratorIterator(self))
+ return GeneratorIterator(self)
else:
return self.execute_frame()
@@ -580,7 +580,7 @@
if w_value is not None:
self.space.setitem_str(d.w_locals, name, w_value)
else:
- w_name = self.space.wrap(name)
+ w_name = self.space.newtext(name)
try:
self.space.delitem(d.w_locals, w_name)
except OperationError as e:
@@ -658,7 +658,7 @@
return None
def fget_code(self, space):
- return space.wrap(self.getcode())
+ return self.getcode()
def fget_getdictscope(self, space):
return self.getdictscope()
@@ -673,9 +673,9 @@
def fget_f_lineno(self, space):
"Returns the line number of the instruction currently being executed."
if self.get_w_f_trace() is None:
- return space.wrap(self.get_last_lineno())
+ return space.newint(self.get_last_lineno())
else:
- return space.wrap(self.getorcreatedebug().f_lineno)
+ return space.newint(self.getorcreatedebug().f_lineno)
def fset_f_lineno(self, space, w_new_lineno):
"Returns the line number of the instruction currently being executed."
@@ -815,10 +815,10 @@
def fget_f_back(self, space):
f_back = ExecutionContext.getnextframe_nohidden(self)
- return self.space.wrap(f_back)
+ return f_back
def fget_f_lasti(self, space):
- return self.space.wrap(self.last_instr)
+ return self.space.newint(self.last_instr)
def fget_f_trace(self, space):
return self.get_w_f_trace()
@@ -858,12 +858,12 @@
while f is not None and f.last_exception is None:
f = f.f_backref()
if f is not None:
- return space.wrap(f.last_exception.get_traceback())
+ return f.last_exception.get_traceback()
return space.w_None
def fget_f_restricted(self, space):
if space.config.objspace.honor__builtins__:
- return space.wrap(self.builtin is not space.builtin)
+ return space.newbool(self.builtin is not space.builtin)
return space.w_False
@jit.unroll_safe
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -84,7 +84,7 @@
rstackovf.check_stack_overflow()
next_instr = self.handle_asynchronous_error(ec,
self.space.w_RuntimeError,
- self.space.wrap("maximum recursion depth exceeded"))
+ self.space.newtext("maximum recursion depth exceeded"))
return next_instr
def handle_asynchronous_error(self, ec, w_type, w_value=None):
@@ -530,7 +530,7 @@
message = ("free variable '%s' referenced before assignment"
" in enclosing scope" % varname)
w_exc_type = self.space.w_NameError
- raise OperationError(w_exc_type, self.space.wrap(message))
+ raise OperationError(w_exc_type, self.space.newtext(message))
else:
self.pushvalue(w_value)
@@ -542,8 +542,7 @@
def LOAD_CLOSURE(self, varindex, next_instr):
# nested scopes: access the cell object
- cell = self._getcell(varindex)
- w_value = self.space.wrap(cell)
+ w_value = self._getcell(varindex)
self.pushvalue(w_value)
def POP_TOP(self, oparg, next_instr):
@@ -959,10 +958,10 @@
for w_t in space.fixedview(w_2):
if space.isinstance_w(w_t, space.w_str):
msg = "catching of string exceptions is deprecated"
- space.warn(space.wrap(msg), space.w_DeprecationWarning)
+ space.warn(space.newtext(msg), space.w_DeprecationWarning)
elif space.isinstance_w(w_2, space.w_str):
msg = "catching of string exceptions is deprecated"
- space.warn(space.wrap(msg), space.w_DeprecationWarning)
+ space.warn(space.newtext(msg), space.w_DeprecationWarning)
return space.newbool(space.exception_match(w_1, w_2))
def COMPARE_OP(self, testnum, next_instr):
@@ -1011,7 +1010,7 @@
w_import = self.get_builtin().getdictvalue(space, '__import__')
if w_import is None:
raise OperationError(space.w_ImportError,
- space.wrap("__import__ not found"))
+ space.newtext("__import__ not found"))
d = self.getdebug()
if d is None:
w_locals = None
@@ -1019,7 +1018,7 @@
w_locals = d.w_locals
if w_locals is None: # CPython does this
w_locals = space.w_None
- w_modulename = space.wrap(modulename)
+ w_modulename = space.newtext(modulename)
w_globals = self.get_w_globals()
if w_flag is None:
w_obj = space.call_function(w_import, w_modulename, w_globals,
@@ -1149,7 +1148,7 @@
# app-level exception
operr = w_unroller.operr
self.last_exception = operr
- w_traceback = self.space.wrap(operr.get_traceback())
+ w_traceback = operr.get_traceback()
w_suppress = self.call_contextmanager_exit_function(
w_exitfunc,
operr.w_type,
@@ -1230,7 +1229,7 @@
defaultarguments = self.popvalues(numdefaults)
fn = function.Function(self.space, codeobj, self.get_w_globals(),
defaultarguments)
- self.pushvalue(self.space.wrap(fn))
+ self.pushvalue(fn)
@jit.unroll_safe
def MAKE_CLOSURE(self, numdefaults, next_instr):
@@ -1242,7 +1241,7 @@
defaultarguments = self.popvalues(numdefaults)
fn = function.Function(self.space, codeobj, self.get_w_globals(),
defaultarguments, freevars)
- self.pushvalue(self.space.wrap(fn))
+ self.pushvalue(fn)
def BUILD_SLICE(self, numargs, next_instr):
if numargs == 3:
@@ -1463,7 +1462,7 @@
# the stack setup is slightly different than in CPython:
# instead of the traceback, we store the unroller object,
# wrapped.
- frame.pushvalue(frame.space.wrap(unroller))
+ frame.pushvalue(unroller)
frame.pushvalue(operationerr.get_w_value(frame.space))
frame.pushvalue(operationerr.w_type)
frame.last_exception = operationerr
@@ -1482,7 +1481,7 @@
# the block unrolling and the entering the finally: handler.
# see comments in cleanup().
self.cleanupstack(frame)
- frame.pushvalue(frame.space.wrap(unroller))
+ frame.pushvalue(unroller)
return r_uint(self.handlerposition) # jump to the handler
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
@@ -12,12 +12,20 @@
self.lastlineno = lastlineno
def wrap_info(self, space):
- return space.newtuple([space.wrap(self.msg),
- space.newtuple([space.wrap(self.filename),
- space.wrap(self.lineno),
- space.wrap(self.offset),
- space.wrap(self.text),
- space.wrap(self.lastlineno)])])
+ if self.filename is None:
+ w_filename = space.w_None
+ else:
+ w_filename = space.newtext(self.filename)
+ if self.text is None:
+ w_text = space.w_None
+ else:
+ w_text = space.newtext(self.text)
+ return space.newtuple([space.newtext(self.msg),
+ space.newtuple([w_filename,
+ space.newint(self.lineno),
+ space.newint(self.offset),
+ w_text,
+ space.newint(self.lastlineno)])])
def __str__(self):
return "%s at pos (%d, %d) in %r" % (self.__class__.__name__,
diff --git a/pypy/interpreter/pytraceback.py b/pypy/interpreter/pytraceback.py
--- a/pypy/interpreter/pytraceback.py
+++ b/pypy/interpreter/pytraceback.py
@@ -24,20 +24,19 @@
return offset2lineno(self.frame.pycode, self.lasti)
def descr_tb_lineno(self, space):
- return space.wrap(self.get_lineno())
+ return space.newint(self.get_lineno())
def descr__reduce__(self, space):
from pypy.interpreter.mixedmodule import MixedModule
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
new_inst = mod.get('traceback_new')
- w = space.wrap
tup_base = []
tup_state = [
- w(self.frame),
- w(self.lasti),
- w(self.next),
+ self.frame,
+ space.newint(self.lasti),
+ self.next,
]
nt = space.newtuple
return nt([new_inst, nt(tup_base), nt(tup_state)])
@@ -61,5 +60,5 @@
def check_traceback(space, w_tb, msg):
if w_tb is None or not space.isinstance_w(w_tb, space.gettypeobject(PyTraceback.typedef)):
- raise OperationError(space.w_TypeError, space.wrap(msg))
+ raise OperationError(space.w_TypeError, space.newtext(msg))
return w_tb
diff --git a/pypy/interpreter/special.py b/pypy/interpreter/special.py
--- a/pypy/interpreter/special.py
+++ b/pypy/interpreter/special.py
@@ -3,9 +3,9 @@
class Ellipsis(W_Root):
def descr__repr__(self, space):
- return space.wrap('Ellipsis')
+ return space.newtext('Ellipsis')
class NotImplemented(W_Root):
def descr__repr__(self, space):
- return space.wrap('NotImplemented')
+ return space.newtext('NotImplemented')
diff --git a/pypy/interpreter/streamutil.py b/pypy/interpreter/streamutil.py
--- a/pypy/interpreter/streamutil.py
+++ b/pypy/interpreter/streamutil.py
@@ -4,7 +4,7 @@
def wrap_streamerror(space, e, w_filename=None):
if isinstance(e, StreamError):
return OperationError(space.w_ValueError,
- space.wrap(e.message))
+ space.newtext(e.message))
elif isinstance(e, OSError):
return wrap_oserror_as_ioerror(space, e, w_filename)
else:
diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -93,6 +93,7 @@
def wrap(self, obj):
return obj
+ newtext = wrap
def str_w(self, s):
return str(s)
More information about the pypy-commit
mailing list