Author: Armin Rigo <[email protected]>
Branch: py3.5-newtext
Changeset: r90136:9f5282f3a6a8
Date: 2017-02-15 08:32 +0100
http://bitbucket.org/pypy/pypy/changeset/9f5282f3a6a8/
Log: hg merge f8751e58e3a8
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -293,7 +293,7 @@
return w_result
if space.isinstance_w(w_result, space.w_int):
tp = space.type(w_result).name
- space.warn(space.wrap(
+ space.warn(space.newtext(
"__int__ returned non-int (type %s). "
"The ability to return an instance of a strict subclass of int
"
"is deprecated, and may be removed in a future version of "
@@ -488,13 +488,13 @@
else:
name = importname
- mod = Module(self, self.wrap(name))
+ mod = Module(self, self.newtext(name))
mod.install()
return name
def getbuiltinmodule(self, name, force_init=False, reuse=True):
- w_name = self.wrap(name)
+ w_name = self.newtext(name)
w_modules = self.sys.get('modules')
if not force_init:
assert reuse
@@ -520,7 +520,7 @@
if not reuse and w_mod.startup_called:
# create a copy of the module. (see issue1514) eventlet
# patcher relies on this behaviour.
- w_mod2 = self.wrap(Module(self, w_name))
+ w_mod2 = Module(self, w_name)
self.setitem(w_modules, w_name, w_mod2)
w_mod.getdict(self) # unlazy w_initialdict
self.call_method(w_mod2.getdict(self), 'update',
@@ -566,26 +566,26 @@
"NOT_RPYTHON: only for initializing the space."
from pypy.module.exceptions import Module
- w_name = self.wrap('__exceptions__')
+ w_name = self.newtext('__exceptions__')
self.exceptions_module = Module(self, w_name)
self.exceptions_module.install()
from pypy.module.imp import Module
- w_name = self.wrap('_imp')
+ w_name = self.newtext('_imp')
mod = Module(self, w_name)
mod.install()
from pypy.module.sys import Module
- w_name = self.wrap('sys')
+ w_name = self.newtext('sys')
self.sys = Module(self, w_name)
self.sys.install()
from pypy.module.__builtin__ import Module
- w_name = self.wrap('builtins')
+ w_name = self.newtext('builtins')
self.builtin = Module(self, w_name)
- w_builtin = self.wrap(self.builtin)
+ w_builtin = self.builtin
w_builtin.install()
- self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), w_builtin)
+ self.setitem(self.builtin.w_dict, self.newtext('__builtins__'),
w_builtin)
# exceptions was bootstrapped as '__exceptions__' but still
# lives in pypy/module/exceptions, we rename it below for
@@ -599,7 +599,7 @@
types_w = (self.get_builtin_types().items() +
exception_types_w.items())
for name, w_type in types_w:
- self.setitem(self.builtin.w_dict, self.wrap(name), w_type)
+ self.setitem(self.builtin.w_dict, self.newtext(name), w_type)
# install mixed modules
for mixedname in self.get_builtinmodule_to_install():
@@ -610,10 +610,10 @@
installed_builtin_modules.append('__exceptions__')
installed_builtin_modules.sort()
w_builtin_module_names = self.newtuple(
- [self.wrap(fn) for fn in installed_builtin_modules])
+ [self.newtext(fn) for fn in installed_builtin_modules])
# force this value into the dict without unlazyfying everything
- self.setitem(self.sys.w_dict, self.wrap('builtin_module_names'),
+ self.setitem(self.sys.w_dict, self.newtext('builtin_module_names'),
w_builtin_module_names)
def get_builtin_types(self):
@@ -741,7 +741,7 @@
# may also override specific functions for performance.
def not_(self, w_obj):
- return self.wrap(not self.is_true(w_obj))
+ return self.newbool(not self.is_true(w_obj))
def eq_w(self, w_obj1, w_obj2):
"""Implements equality with the double check 'x is y or x == y'."""
@@ -767,7 +767,7 @@
w_result = w_obj.immutable_unique_id(self)
if w_result is None:
# in the common case, returns an unsigned value
- w_result = self.wrap(r_uint(compute_unique_id(w_obj)))
+ w_result = self.newint(r_uint(compute_unique_id(w_obj)))
return w_result
def hash_w(self, w_obj):
@@ -783,10 +783,10 @@
return self.is_true(self.contains(w_container, w_item))
def setitem_str(self, w_obj, key, w_value):
- return self.setitem(w_obj, self.wrap(key), w_value)
+ return self.setitem(w_obj, self.newtext(key), w_value)
def finditem_str(self, w_obj, key):
- return self.finditem(w_obj, self.wrap(key))
+ return self.finditem(w_obj, self.newtext(key))
def finditem(self, w_obj, w_key):
try:
@@ -1064,13 +1064,13 @@
return self.newlist([self.newbytes(s) for s in list_s])
def newlist_unicode(self, list_u):
- return self.newlist([self.wrap(u) for u in list_u])
+ return self.newlist([self.newunicode(u) for u in list_u])
def newlist_int(self, list_i):
- return self.newlist([self.wrap(i) for i in list_i])
+ return self.newlist([self.newint(i) for i in list_i])
def newlist_float(self, list_f):
- return self.newlist([self.wrap(f) for f in list_f])
+ return self.newlist([self.newfloat(f) for f in list_f])
def newlist_hint(self, sizehint):
from pypy.objspace.std.listobject import make_empty_list_with_size
@@ -1166,7 +1166,7 @@
return w_res
def call_method(self, w_obj, methname, *arg_w):
- w_meth = self.getattr(w_obj, self.wrap(methname))
+ w_meth = self.getattr(w_obj, self.newtext(methname))
return self.call_function(w_meth, *arg_w)
def raise_key_error(self, w_key):
@@ -1175,7 +1175,7 @@
def lookup(self, w_obj, name):
w_type = self.type(w_obj)
- w_mro = self.getattr(w_type, self.wrap("__mro__"))
+ w_mro = self.getattr(w_type, self.newtext("__mro__"))
for w_supertype in self.fixedview(w_mro):
w_value = w_supertype.getdictvalue(self, name)
if w_value is not None:
@@ -1187,7 +1187,7 @@
return isinstance(w_obj, GeneratorIterator)
def callable(self, w_obj):
- return self.wrap(self.lookup(w_obj, "__call__") is not None)
+ return self.newbool(self.lookup(w_obj, "__call__") is not None)
def issequence_w(self, w_obj):
flag = self.type(w_obj).flag_map_or_seq
@@ -1230,7 +1230,7 @@
def isabstractmethod_w(self, w_obj):
try:
- w_result = self.getattr(w_obj, self.wrap("__isabstractmethod__"))
+ w_result = self.getattr(w_obj,
self.newtext("__isabstractmethod__"))
except OperationError as e:
if e.match(self, self.w_AttributeError):
return False
@@ -1283,9 +1283,9 @@
hidden_applevel=hidden_applevel)
if not isinstance(statement, PyCode):
raise TypeError('space.exec_(): expected a string, code or PyCode
object')
- w_key = self.wrap('__builtins__')
+ w_key = self.newtext('__builtins__')
if not self.contains_w(w_globals, w_key):
- self.setitem(w_globals, w_key, self.wrap(self.builtin))
+ self.setitem(w_globals, w_key, self.builtin)
return statement.exec_code(self, w_globals, w_locals)
@specialize.arg(2)
@@ -1396,7 +1396,7 @@
raise
if not w_exception:
# w_index should be a long object, but can't be sure of that
- if self.is_true(self.lt(w_index, self.wrap(0))):
+ if self.is_true(self.lt(w_index, self.newint(0))):
return -sys.maxint-1
else:
return sys.maxint
@@ -1820,7 +1820,7 @@
# with a fileno(), but not an object with an __int__().
if not self.isinstance_w(w_fd, self.w_int):
try:
- w_fileno = self.getattr(w_fd, self.wrap("fileno"))
+ w_fileno = self.getattr(w_fd, self.newtext("fileno"))
except OperationError as e:
if e.match(self, self.w_AttributeError):
raise oefmt(self.w_TypeError,
diff --git a/pypy/module/_rawffi/interp_rawffi.py
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -444,13 +444,16 @@
if c in TYPEMAP_PTR_LETTERS:
res = func(add_arg, argdesc, rffi.VOIDP)
return space.newint(rffi.cast(lltype.Unsigned, res))
+ if c in TYPEMAP_NUMBER_LETTERS:
+ return space.newint(func(add_arg, argdesc, ll_type))
elif c == 'c':
return space.newbytes(func(add_arg, argdesc, ll_type))
+ elif c == 'u':
+ return space.newunicode(func(add_arg, argdesc, ll_type))
elif c == 'f' or c == 'd' or c == 'g':
return space.newfloat(float(func(add_arg, argdesc, ll_type)))
else:
- # YYY hard
- return space.wrap(func(add_arg, argdesc, ll_type))
+ assert 0, "unreachable"
raise oefmt(space.w_TypeError, "cannot directly read value")
NARROW_INTEGER_TYPES = 'cbhiBIH?'
diff --git a/pypy/module/array/interp_array.py
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -1049,15 +1049,20 @@
if mytype.typecode in 'bBhHil':
item = rffi.cast(lltype.Signed, item)
return space.newint(item)
- elif mytype.typecode == 'f':
+ if mytype.typecode in 'ILqQ':
+ return space.newint(item)
+ elif mytype.typecode in 'fd':
item = float(item)
return space.newfloat(item)
+ elif mytype.typecode == 'c':
+ return space.newbytes(item)
elif mytype.typecode == 'u':
if ord(item) >= 0x110000:
raise oefmt(space.w_ValueError,
"array contains a unicode character out of "
"range(0x110000)")
- return space.wrap(item) # YYY
+ return space.newunicode(item)
+ assert 0, "unreachable"
# interface
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -15,7 +15,9 @@
def startup(self, space):
space.fromcache(State).startup(space)
method = pypy.module.cpyext.typeobject.get_new_method_def(space)
- w_obj = pypy.module.cpyext.methodobject.W_PyCFunctionObject(space,
method, space.wrap(''))
+ # the w_self argument here is a dummy, the only thing done with w_obj
+ # is call space.type on it
+ w_obj = pypy.module.cpyext.methodobject.W_PyCFunctionObject(space,
method, space.w_None)
space.appexec([space.type(w_obj)], """(methodtype):
from pickle import Pickler
Pickler.dispatch[methodtype] = Pickler.save_global
diff --git a/pypy/module/cpyext/ndarrayobject.py
b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -264,7 +264,7 @@
w_dtypes = space.newlist(dtypes_w)
w_doc = rffi.charp2str(doc)
w_name = rffi.charp2str(name)
- w_identity = space.wrap(identity)
+ w_identity = space.newint(identity)
ufunc_generic = ufuncs.frompyfunc(space, w_funcs, nin, nout, w_dtypes,
w_signature, w_identity, w_name, w_doc, stack_inputs=True)
return ufunc_generic
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
@@ -73,7 +73,7 @@
w_result = PyUnicode_FromString(space, result)
elif member_type == T_CHAR:
result = rffi.cast(rffi.CCHARP, addr)
- w_result = space.wrap(result[0])
+ w_result = space.newtext(result[0])
elif member_type == T_OBJECT:
obj_ptr = rffi.cast(PyObjectP, addr)
if obj_ptr[0]:
diff --git a/pypy/module/micronumpy/appbridge.py
b/pypy/module/micronumpy/appbridge.py
--- a/pypy/module/micronumpy/appbridge.py
+++ b/pypy/module/micronumpy/appbridge.py
@@ -18,7 +18,7 @@
def call_method(self, space, path, name, args):
w_method = getattr(self, 'w_' + name)
if w_method is None:
- w_method = space.appexec([space.wrap(path), space.wrap(name)],
+ w_method = space.appexec([space.newtext(path),
space.newtext(name)],
"(path, name): return getattr(__import__(path,
fromlist=[name]), name)")
setattr(self, 'w_' + name, w_method)
return space.call_args(w_method, args)
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -602,7 +602,8 @@
class W_CharacterBox(W_FlexibleBox):
def convert_to(self, space, dtype):
- return dtype.coerce(space, space.wrap(self.raw_str()))
+ # XXX should be newbytes?
+ return dtype.coerce(space, space.newtext(self.raw_str()))
def descr_len(self, space):
return space.len(self.item(space))
diff --git a/pypy/module/micronumpy/compile.py
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -411,9 +411,12 @@
def newdict(self, module=True):
return DictObject({})
+ @specialize.argtype(1)
def newint(self, i):
if isinstance(i, IntObject):
return i
+ if isinstance(i, base_int):
+ return LongObject(i)
return IntObject(i)
def setitem(self, obj, index, value):
diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -468,7 +468,7 @@
val = dtype.itemtype.default_fromstring(space)
else:
try:
- val = dtype.coerce(space, space.wrap(piece))
+ val = dtype.coerce(space, space.newtext(piece))
except OperationError as e:
if not e.match(space, space.w_ValueError):
raise
@@ -476,7 +476,7 @@
while not gotit and len(piece) > 0:
piece = piece[:-1]
try:
- val = dtype.coerce(space, space.wrap(piece))
+ val = dtype.coerce(space, space.newtext(piece))
gotit = True
except OperationError as e:
if not e.match(space, space.w_ValueError):
diff --git a/pypy/module/micronumpy/ndarray.py
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -1263,7 +1263,7 @@
op_name, self.get_dtype().get_name())
shape = self.get_shape()
if space.is_none(w_axis) or len(shape) <= 1:
- return space.wrap(getattr(loop, op_name_flat)(self))
+ return space.newint(getattr(loop, op_name_flat)(self))
else:
axis = space.int_w(w_axis)
assert axis >= 0
@@ -1340,7 +1340,7 @@
assert isinstance(multiarray, MixedModule)
reconstruct = multiarray.get("_reconstruct")
parameters = space.newtuple([self.getclass(space), space.newtuple(
- [space.newint(0)]), space.wrap("b")])
+ [space.newint(0)]), space.newtext("b")])
builder = StringBuilder()
if self.get_dtype().is_object():
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -462,7 +462,7 @@
signed = True
def to_builtin_type(self, space, box):
- return space.wrap(self.for_computation(self.unbox(box)))
+ return space.newint(self.for_computation(self.unbox(box)))
def _base_coerce(self, space, w_item):
if w_item is None:
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -1206,7 +1206,7 @@
nargs = interp_attrproperty("nargs", cls=W_Ufunc,
wrapfn="newint"),
signature = interp_attrproperty("signature", cls=W_Ufunc,
- wrapfn="newtext"),
+ wrapfn="newtext_or_none"),
reduce = interp2app(W_Ufunc.descr_reduce),
outer = interp2app(W_Ufunc.descr_outer),
diff --git a/pypy/module/struct/formatiterator.py
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -147,10 +147,17 @@
@specialize.argtype(1)
def appendobj(self, value):
- if isinstance(value, str):
- self.result_w.append(self.space.newbytes(value))
+ if isinstance(value, float):
+ w_value = self.space.newfloat(value)
+ elif isinstance(value, str):
+ w_value = self.space.newbytes(value)
+ elif isinstance(value, unicode):
+ w_value = self.space.newunicode(value)
+ elif isinstance(value, bool):
+ w_value = self.space.newbool(value)
else:
- self.result_w.append(self.space.wrap(value)) # YYY
+ w_value = self.space.newint(value)
+ self.result_w.append(w_value)
def get_pos(self):
return self.pos
diff --git a/pypy/module/sys/currentframes.py b/pypy/module/sys/currentframes.py
--- a/pypy/module/sys/currentframes.py
+++ b/pypy/module/sys/currentframes.py
@@ -64,7 +64,7 @@
w_topframe = space.w_None
w_prevframe = None
for f in frames:
- w_nextframe = space.call_function(w_fake_frame, space.wrap(f))
+ w_nextframe = space.call_function(w_fake_frame, space.wrap_none(f))
if w_prevframe is None:
w_topframe = w_nextframe
else:
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -178,6 +178,7 @@
W_SliceObject(w_start, w_end, w_step)
return w_some_obj()
+ @specialize.argtype(1)
def newint(self, x):
return w_some_obj()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit