Author: Carl Friedrich Bolz <[email protected]>
Branch: space-newtext
Changeset: r88792:00b54f1e2516
Date: 2016-12-01 15:05 +0100
http://bitbucket.org/pypy/pypy/changeset/00b54f1e2516/
Log: str_w in micronumpy
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -403,7 +403,7 @@
Supports the standard %s and %d formats, plus the following:
%N - The result of w_arg.getname(space)
- %R - The result of space.str_w(space.repr(w_arg))
+ %R - The result of space.text_w(space.repr(w_arg))
%T - The result of space.type(w_arg).name
"""
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
@@ -556,7 +556,7 @@
class W_VoidBox(W_FlexibleBox):
def descr_getitem(self, space, w_item):
if space.isinstance_w(w_item, space.w_basestring):
- item = space.str_w(w_item)
+ item = space.text_w(w_item)
elif space.isinstance_w(w_item, space.w_int):
indx = space.int_w(w_item)
try:
@@ -587,7 +587,7 @@
def descr_setitem(self, space, w_item, w_value):
if space.isinstance_w(w_item, space.w_basestring):
- item = space.str_w(w_item)
+ item = space.text_w(w_item)
elif space.isinstance_w(w_item, space.w_int):
indx = space.int_w(w_item)
try:
@@ -622,7 +622,7 @@
class W_StringBox(W_CharacterBox):
def descr__new__string_box(space, w_subtype, w_arg):
from pypy.module.micronumpy.descriptor import new_string_dtype
- arg = space.str_w(space.str(w_arg))
+ arg = space.text_w(space.str(w_arg))
arr = VoidBoxStorage(len(arg), new_string_dtype(space, len(arg)))
for i in range(len(arg)):
arr.storage[i] = arg[i]
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
@@ -76,6 +76,7 @@
w_tuple = W_TypeObject('tuple')
w_slice = W_TypeObject("slice")
w_str = W_TypeObject("str")
+ w_bytes = w_str
w_unicode = W_TypeObject("unicode")
w_complex = W_TypeObject("complex")
w_dict = W_TypeObject("dict")
diff --git a/pypy/module/micronumpy/converters.py
b/pypy/module/micronumpy/converters.py
--- a/pypy/module/micronumpy/converters.py
+++ b/pypy/module/micronumpy/converters.py
@@ -25,8 +25,8 @@
def clipmode_converter(space, w_mode):
if space.is_none(w_mode):
return NPY.RAISE
- if space.isinstance_w(w_mode, space.w_str):
- mode = space.str_w(w_mode)
+ if space.isinstance_w(w_mode, space.w_text):
+ mode = space.text_w(w_mode)
if mode.startswith('C') or mode.startswith('c'):
return NPY.CLIP
if mode.startswith('W') or mode.startswith('w'):
@@ -42,7 +42,7 @@
def searchside_converter(space, w_obj):
try:
- s = space.str_w(w_obj)
+ s = space.text_w(w_obj)
except OperationError:
s = None
if not s:
@@ -66,7 +66,7 @@
else:
return NPY.CORDER
else:
- order = space.str_w(w_order)
+ order = space.text_w(w_order)
if order.startswith('C') or order.startswith('c'):
return NPY.CORDER
elif order.startswith('F') or order.startswith('f'):
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
@@ -20,11 +20,11 @@
"argument 1 must be numpy.dtype, not %T", w_dtype)
if w_dtype.elsize == 0:
raise oefmt(space.w_TypeError, "Empty data-type")
- if not space.isinstance_w(w_state, space.w_str):
+ if not space.isinstance_w(w_state, space.w_bytes): # py3 accepts unicode
here too
raise oefmt(space.w_TypeError, "initializing object must be a string")
if space.len_w(w_state) != w_dtype.elsize:
raise oefmt(space.w_ValueError, "initialization string is too small")
- state = rffi.str2charp(space.str_w(w_state))
+ state = rffi.str2charp(space.text_w(w_state))
box = w_dtype.itemtype.box_raw_data(state)
lltype.free(state, flavor="raw")
return box
@@ -212,7 +212,7 @@
if not isinstance(w_object, W_NDimArray):
w_array = try_array_method(space, w_object, w_dtype)
if w_array is None:
- if ( not space.isinstance_w(w_object, space.w_str) and
+ if ( not space.isinstance_w(w_object, space.w_bytes) and
not space.isinstance_w(w_object, space.w_unicode) and
not isinstance(w_object, W_GenericBox)):
# use buffer interface
@@ -323,7 +323,7 @@
return _find_shape_and_elems(space, w_iterable, is_rec_type)
def is_scalar_like(space, w_obj, dtype):
- isstr = space.isinstance_w(w_obj, space.w_str)
+ isstr = space.isinstance_w(w_obj, space.w_bytes)
if not support.issequence_w(space, w_obj) or isstr:
if dtype is None or dtype.char != NPY.CHARLTR:
return True
diff --git a/pypy/module/micronumpy/descriptor.py
b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -40,7 +40,7 @@
return out
def byteorder_w(space, w_str):
- order = space.str_w(w_str)
+ order = space.text_w(w_str)
if len(order) != 1:
raise oefmt(space.w_ValueError,
"endian is not 1-char string in Numpy dtype unpickling")
@@ -275,13 +275,13 @@
for name, title in self.names:
offset, subdtype = self.fields[name]
if subdtype.is_record():
- substr = [space.str_w(space.str(subdtype.descr_get_descr(
+ substr = [space.text_w(space.str(subdtype.descr_get_descr(
space,
style='descr_subdtype'))), ","]
elif subdtype.subdtype is not None:
- substr = ["(", space.str_w(space.str(
+ substr = ["(", space.text_w(space.str(
subdtype.subdtype.descr_get_descr(space,
style='descr_subdtype'))),
', ',
- space.str_w(space.repr(space.newtuple([space.newint(s)
for s in subdtype.shape]))),
+
space.text_w(space.repr(space.newtuple([space.newint(s) for s in
subdtype.shape]))),
"),"]
else:
substr = ["'", subdtype.get_str(ignore=''), "',"]
@@ -351,7 +351,7 @@
subdescr.append(subdtype.descr_get_shape(space))
descr.append(space.newtuple(subdescr[:]))
if self.alignment >= 0 and not style.endswith('subdtype'):
- return
space.newtext(space.str_w(space.repr(space.newlist(descr))) + ', align=True')
+ return
space.newtext(space.text_w(space.repr(space.newlist(descr))) + ', align=True')
return space.newlist(descr)
def descr_get_hasobject(self, space):
@@ -418,7 +418,7 @@
raise oefmt(space.w_ValueError,
"item #%d of names is of type %T and not string",
len(names), w_name)
- names.append((space.str_w(w_name), title))
+ names.append((space.text_w(w_name), title))
fields = {}
for i in range(len(self.names)):
if names[i][0] in fields:
@@ -523,7 +523,7 @@
def descr_str(self, space):
if self.fields:
r = self.descr_get_descr(space, style='str')
- name = space.str_w(space.str(self.w_box_type))
+ name = space.text_w(space.str(self.w_box_type))
if name != "<type 'numpy.void'>":
boxname = space.str(self.w_box_type)
r = space.newtuple([self.w_box_type, r])
@@ -543,7 +543,7 @@
return space.newtext("dtype('S1')")
if self.fields:
r = self.descr_get_descr(space, style='repr')
- name = space.str_w(space.str(self.w_box_type))
+ name = space.text_w(space.str(self.w_box_type))
if name != "<type 'numpy.void'>":
r = space.newtuple([self.w_box_type, r])
elif self.subdtype is not None:
@@ -562,15 +562,15 @@
else:
r = self.descr_get_name(space, quote=True)
if space.isinstance_w(r, space.w_str):
- return space.newtext("dtype(%s)" % space.str_w(r))
- return space.newtext("dtype(%s)" % space.str_w(space.repr(r)))
+ return space.newtext("dtype(%s)" % space.text_w(r))
+ return space.newtext("dtype(%s)" % space.text_w(space.repr(r)))
def descr_getitem(self, space, w_item):
if not self.fields:
raise oefmt(space.w_KeyError, "There are no fields in dtype %s.",
self.get_name())
if space.isinstance_w(w_item, space.w_basestring):
- item = space.str_w(w_item)
+ item = space.text_w(w_item)
elif space.isinstance_w(w_item, space.w_int):
indx = space.int_w(w_item)
try:
@@ -749,15 +749,15 @@
w_flddesc, maxalign, w_shape=w_shape)
if space.isinstance_w(w_fldname, space.w_tuple):
fldlist = space.listview(w_fldname)
- fldnames[i] = space.str_w(fldlist[0])
+ fldnames[i] = space.text_w(fldlist[0])
if space.is_w(fldlist[1], space.w_None):
titles[i] = None
else:
- titles[i] = space.str_w(fldlist[1])
+ titles[i] = space.text_w(fldlist[1])
if len(fldlist) != 2:
raise oefmt(space.w_TypeError, "data type not understood")
elif space.isinstance_w(w_fldname, space.w_str):
- fldnames[i] = space.str_w(w_fldname)
+ fldnames[i] = space.text_w(w_fldname)
else:
raise oefmt(space.w_TypeError, "data type not understood")
if fldnames[i] == '':
@@ -851,7 +851,7 @@
# Only for testing, a shortened version of the real _usefields
allfields = []
for fname_w in space.unpackiterable(w_dict):
- obj = _get_list_or_none(space, w_dict, space.str_w(fname_w))
+ obj = _get_list_or_none(space, w_dict, space.text_w(fname_w))
num = space.int_w(obj[1])
if align:
alignment = 0
diff --git a/pypy/module/micronumpy/flagsobj.py
b/pypy/module/micronumpy/flagsobj.py
--- a/pypy/module/micronumpy/flagsobj.py
+++ b/pypy/module/micronumpy/flagsobj.py
@@ -61,7 +61,7 @@
return space.newint(self.flags)
def descr_getitem(self, space, w_item):
- key = space.str_w(w_item)
+ key = space.text_w(w_item)
if key == "C" or key == "CONTIGUOUS" or key == "C_CONTIGUOUS":
return self.descr_c_contiguous(space)
if key == "F" or key == "FORTRAN" or key == "F_CONTIGUOUS":
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
@@ -250,8 +250,8 @@
def descr_getitem(self, space, w_idx):
if self.get_dtype().is_record():
- if space.isinstance_w(w_idx, space.w_str):
- idx = space.str_w(w_idx)
+ if space.isinstance_w(w_idx, space.w_text):
+ idx = space.text_w(w_idx)
return self.getfield(space, idx)
if space.is_w(w_idx, space.w_Ellipsis):
return self.descr_view(space, space.type(self))
@@ -287,8 +287,8 @@
def descr_setitem(self, space, w_idx, w_value):
if self.get_dtype().is_record():
- if space.isinstance_w(w_idx, space.w_str):
- idx = space.str_w(w_idx)
+ if space.isinstance_w(w_idx, space.w_text):
+ idx = space.text_w(w_idx)
view = self.getfield(space, idx)
w_value = convert_to_array(space, w_value)
view.implementation.setslice(space, w_value)
@@ -735,10 +735,9 @@
# XXX Should not happen
raise oefmt(space.w_ValueError, "new dtype has elsize of 0")
if not can_cast_array(space, self, new_dtype, casting):
- raise oefmt(space.w_TypeError, "Cannot cast array from %s to %s"
- "according to the rule %s",
- space.str_w(self.get_dtype().descr_repr(space)),
- space.str_w(new_dtype.descr_repr(space)), casting)
+ raise oefmt(space.w_TypeError, "Cannot cast array from %R to %R"
+ "according to the rule %s", self.get_dtype(),
+ new_dtype, casting)
order = order_converter(space, space.newtext(order), self.get_order())
if (not copy and new_dtype == self.get_dtype()
and (order in (NPY.KEEPORDER, NPY.ANYORDER) or order ==
self.get_order())
diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py
--- a/pypy/module/micronumpy/nditer.py
+++ b/pypy/module/micronumpy/nditer.py
@@ -53,7 +53,7 @@
def parse_op_flag(space, lst):
op_flag = OpFlag()
for w_item in lst:
- item = space.str_w(w_item)
+ item = space.text_w(w_item)
if item == 'readonly':
op_flag.rw = 'r'
elif item == 'readwrite':
@@ -102,12 +102,12 @@
'Iter global flags must be a list or tuple of strings')
lst = space.listview(w_flags)
for w_item in lst:
- if not space.isinstance_w(w_item, space.w_str) and not \
+ if not space.isinstance_w(w_item, space.w_bytes) and not \
space.isinstance_w(w_item, space.w_unicode):
raise oefmt(space.w_TypeError,
"expected string or Unicode object, %T found",
w_item)
- item = space.str_w(w_item)
+ item = space.text_w(w_item)
if item == 'external_loop':
nditer.external_loop = True
elif item == 'buffered':
@@ -365,7 +365,7 @@
self.op_axes = []
self.allow_backward = allow_backward
if not space.is_w(w_casting, space.w_None):
- self.casting = space.str_w(w_casting)
+ self.casting = space.text_w(w_casting)
else:
self.casting = 'safe'
# convert w_seq operands to a list of W_NDimArray
@@ -483,11 +483,9 @@
if not can_cast_array(
space, self.seq[i], self_d, self.casting):
raise oefmt(space.w_TypeError, "Iterator
operand %d"
- " dtype could not be cast from %s to %s"
- " according to the rule '%s'", i,
- space.str_w(seq_d.descr_repr(space)),
- space.str_w(self_d.descr_repr(space)),
- self.casting)
+ " dtype could not be cast from %R to %R"
+ " according to the rule '%s'",
+ i, seq_d, self_d, self.casting)
order = support.get_order_as_CF(impl.order,
self.order)
new_impl = impl.astype(space, self_d,
order).copy(space)
self.seq[i] = W_NDimArray(new_impl)
@@ -501,11 +499,9 @@
space, self_d, seq_d, self.casting):
raise oefmt(space.w_TypeError, "Iterator"
" requested dtype could not be cast from "
- " %s to %s, the operand %d dtype, accord"
- "ing to the rule '%s'",
- space.str_w(self_d.descr_repr(space)),
- space.str_w(seq_d.descr_repr(space)),
- i, self.casting)
+ " %R to %R, the operand %d dtype, accord"
+ "ing to the rule '%s'",
+ self_d, seq_d, i, self.casting)
elif self.buffered and not (self.external_loop and len(self.seq)<2):
for i in range(len(self.seq)):
if i not in outargs:
diff --git a/pypy/module/micronumpy/support.py
b/pypy/module/micronumpy/support.py
--- a/pypy/module/micronumpy/support.py
+++ b/pypy/module/micronumpy/support.py
@@ -205,7 +205,7 @@
if space.is_none(w_docstring):
doc = None
else:
- doc = space.str_w(w_docstring)
+ doc = space.text_w(w_docstring)
w_obj.doc = doc
return
app_set_docstring(space, w_obj, w_docstring)
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
@@ -1929,12 +1929,12 @@
def str_format(self, box, add_quotes=True):
if not add_quotes:
- as_str = self.space.str_w(self.space.repr(self.unbox(box)))
+ as_str = self.space.text_w(self.space.repr(self.unbox(box)))
as_strl = len(as_str) - 1
if as_strl>1 and as_str[0] == "'" and as_str[as_strl] == "'":
as_str = as_str[1:as_strl]
return as_str
- return self.space.str_w(self.space.repr(self.unbox(box)))
+ return self.space.text_w(self.space.repr(self.unbox(box)))
def runpack_str(self, space, s, native):
raise oefmt(space.w_NotImplementedError,
@@ -2165,7 +2165,7 @@
return w_item
if w_item is None:
w_item = space.newbytes('')
- arg = space.str_w(space.str(w_item))
+ arg = space.text_w(space.str(w_item))
arr = VoidBoxStorage(dtype.elsize, dtype)
with arr as storage:
j = min(len(arg), dtype.elsize)
@@ -2314,7 +2314,7 @@
assert isinstance(item, boxes.W_UnicodeBox)
if add_quotes:
w_unicode = self.to_builtin_type(self.space, item)
- return self.space.str_w(self.space.repr(w_unicode))
+ return self.space.text_w(self.space.repr(w_unicode))
else:
# Same as W_UnicodeBox.descr_repr() but without quotes and prefix
from rpython.rlib.runicode import unicode_encode_unicode_escape
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
@@ -153,7 +153,7 @@
if w_casting is None:
casting = 'unsafe'
else:
- casting = space.str_w(w_casting)
+ casting = space.text_w(w_casting)
retval = self.call(space, args_w, sig, casting, extobj)
keepalive_until_here(args_w)
return retval
@@ -983,7 +983,7 @@
if sig:
raise oefmt(space.w_RuntimeError,
"cannot specify both 'sig' and 'dtype'")
- sig = space.str_w(kwargs_w[kw])
+ sig = space.text_w(kwargs_w[kw])
parsed_kw.append(kw)
elif kw.startswith('where'):
raise oefmt(space.w_NotImplementedError,
@@ -1504,7 +1504,7 @@
elif (space.isinstance_w(w_dtypes, space.w_tuple) or
space.isinstance_w(w_dtypes, space.w_list)):
_dtypes = space.listview(w_dtypes)
- if space.isinstance_w(_dtypes[0], space.w_str) and
space.str_w(_dtypes[0]) == 'match':
+ if space.isinstance_w(_dtypes[0], space.w_text) and
space.text_w(_dtypes[0]) == 'match':
dtypes = []
match_dtypes = True
else:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit