aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pypy/objspace/descroperation.py28
-rw-r--r--pypy/objspace/std/bytesobject.py4
-rw-r--r--pypy/objspace/std/dictproxyobject.py3
-rw-r--r--pypy/objspace/std/formatting.py54
-rw-r--r--pypy/objspace/std/listobject.py29
-rw-r--r--pypy/objspace/std/mapdict.py5
-rw-r--r--pypy/objspace/std/newformat.py116
-rw-r--r--pypy/objspace/std/objectobject.py3
-rw-r--r--pypy/objspace/std/objspace.py12
-rw-r--r--pypy/objspace/std/proxyobject.py7
-rw-r--r--pypy/objspace/std/setobject.py19
-rw-r--r--pypy/objspace/std/sliceobject.py20
-rw-r--r--pypy/objspace/std/specialisedtupleobject.py8
-rw-r--r--pypy/objspace/std/transparent.py4
-rw-r--r--pypy/objspace/std/tupleobject.py8
-rw-r--r--pypy/objspace/std/typeobject.py6
-rw-r--r--pypy/objspace/std/unicodeobject.py4
-rw-r--r--pypy/tool/pytest/appsupport.py10
18 files changed, 148 insertions, 192 deletions
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
index ed1a7ce2df..22b70b7886 100644
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -247,8 +247,8 @@ class DescrOperation(object):
if space.is_w(w_restype, space.w_int):
return space.int_w(w_res) != 0
else:
- msg = "__nonzero__ should return bool or integer"
- raise OperationError(space.w_TypeError, space.wrap(msg))
+ raise oefmt(space.w_TypeError,
+ "__nonzero__ should return bool or integer")
def nonzero(space, w_obj):
if space.is_true(w_obj):
@@ -282,8 +282,7 @@ class DescrOperation(object):
w_iter = space.get_and_call_function(w_descr, w_obj)
w_next = space.lookup(w_iter, 'next')
if w_next is None:
- raise OperationError(space.w_TypeError,
- space.wrap("iter() returned non-iterator"))
+ raise oefmt(space.w_TypeError, "iter() returned non-iterator")
return w_iter
def next(space, w_obj):
@@ -382,8 +381,7 @@ class DescrOperation(object):
if _check_notimplemented(space, w_res):
return w_res
- raise OperationError(space.w_TypeError,
- space.wrap("operands do not support **"))
+ raise oefmt(space.w_TypeError, "operands do not support **")
def inplace_pow(space, w_lhs, w_rhs):
w_impl = space.lookup(w_lhs, '__ipow__')
@@ -439,8 +437,8 @@ class DescrOperation(object):
bigint = space.bigint_w(w_result)
return space.wrap(bigint.hash())
else:
- raise OperationError(space.w_TypeError,
- space.wrap("__hash__() should return an int or long"))
+ raise oefmt(space.w_TypeError,
+ "__hash__() should return an int or long")
def userdel(space, w_obj):
w_del = space.lookup(w_obj, '__del__')
@@ -469,8 +467,7 @@ class DescrOperation(object):
def coerce(space, w_obj1, w_obj2):
w_res = space.try_coerce(w_obj1, w_obj2)
if w_res is None:
- raise OperationError(space.w_TypeError,
- space.wrap("coercion failed"))
+ raise oefmt(space.w_TypeError, "coercion failed")
return w_res
def try_coerce(space, w_obj1, w_obj2):
@@ -494,13 +491,13 @@ class DescrOperation(object):
return None
if (not space.isinstance_w(w_res, space.w_tuple) or
space.len_w(w_res) != 2):
- raise OperationError(space.w_TypeError,
- space.wrap("coercion should return None or 2-tuple"))
+ raise oefmt(space.w_TypeError,
+ "coercion should return None or 2-tuple")
w_res = space.newtuple([space.getitem(w_res, space.wrap(1)), space.getitem(w_res, space.wrap(0))])
elif (not space.isinstance_w(w_res, space.w_tuple) or
space.len_w(w_res) != 2):
- raise OperationError(space.w_TypeError,
- space.wrap("coercion should return None or 2-tuple"))
+ raise oefmt(space.w_TypeError,
+ "coercion should return None or 2-tuple")
return w_res
def issubtype(space, w_sub, w_type):
@@ -517,8 +514,7 @@ class DescrOperation(object):
def issubtype_allow_override(space, w_sub, w_type):
w_check = space.lookup(w_type, "__subclasscheck__")
if w_check is None:
- raise OperationError(space.w_TypeError,
- space.wrap("issubclass not supported here"))
+ raise oefmt(space.w_TypeError, "issubclass not supported here")
return space.get_and_call_function(w_check, w_type, w_sub)
def isinstance_allow_override(space, w_inst, w_type):
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
index c58b14cb5a..412750571e 100644
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -446,8 +446,8 @@ class W_BytesObject(W_AbstractBytesObject):
return StringBuffer(self._value)
def writebuf_w(self, space):
- raise OperationError(space.w_TypeError, space.wrap(
- "Cannot use string as modifiable buffer"))
+ raise oefmt(space.w_TypeError,
+ "Cannot use string as modifiable buffer")
charbuf_w = str_w
diff --git a/pypy/objspace/std/dictproxyobject.py b/pypy/objspace/std/dictproxyobject.py
index 7682bd29fe..5cebe1d62d 100644
--- a/pypy/objspace/std/dictproxyobject.py
+++ b/pypy/objspace/std/dictproxyobject.py
@@ -41,7 +41,8 @@ class DictProxyStrategy(DictStrategy):
if space.is_w(space.type(w_key), space.w_str):
self.setitem_str(w_dict, self.space.str_w(w_key), w_value)
else:
- raise OperationError(space.w_TypeError, space.wrap("cannot add non-string keys to dict of a type"))
+ raise oefmt(space.w_TypeError,
+ "cannot add non-string keys to dict of a type")
def setitem_str(self, w_dict, key, w_value):
w_type = self.unerase(w_dict.dstorage)
diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py
index 695fab3050..47c739d6be 100644
--- a/pypy/objspace/std/formatting.py
+++ b/pypy/objspace/std/formatting.py
@@ -28,27 +28,24 @@ class BaseStringFormatter(object):
try:
w_result = self.values_w[self.values_pos]
except IndexError:
- space = self.space
- raise OperationError(space.w_TypeError, space.wrap(
- 'not enough arguments for format string'))
+ raise oefmt(self.space.w_TypeError,
+ "not enough arguments for format string")
else:
self.values_pos += 1
return w_result
def checkconsumed(self):
if self.values_pos < len(self.values_w) and self.w_valuedict is None:
- space = self.space
- raise OperationError(space.w_TypeError,
- space.wrap('not all arguments converted '
- 'during string formatting'))
+ raise oefmt(self.space.w_TypeError,
+ "not all arguments converted during string formatting")
def std_wp_int(self, r, prefix='', keep_zero=False):
# use self.prec to add some '0' on the left of the number
if self.prec >= 0:
if self.prec > 1000:
- raise OperationError(
- self.space.w_OverflowError, self.space.wrap(
- 'formatted integer is too long (precision too large?)'))
+ raise oefmt(self.space.w_OverflowError,
+ "formatted integer is too long (precision too "
+ "large?)")
sign = r[0] == '-'
padding = self.prec - (len(r)-int(sign))
if padding > 0:
@@ -170,9 +167,7 @@ def make_formatter_subclass(do_unicode):
try:
return self.fmt[self.fmtpos]
except IndexError:
- space = self.space
- raise OperationError(space.w_ValueError,
- space.wrap("incomplete format"))
+ raise oefmt(self.space.w_ValueError, "incomplete format")
# Only shows up if we've already started inlining format(), so just
# unconditionally unroll this.
@@ -188,8 +183,7 @@ def make_formatter_subclass(do_unicode):
c = fmt[i]
except IndexError:
space = self.space
- raise OperationError(space.w_ValueError,
- space.wrap("incomplete format key"))
+ raise oefmt(space.w_ValueError, "incomplete format key")
if c == ')':
pcount -= 1
if pcount == 0:
@@ -204,8 +198,7 @@ def make_formatter_subclass(do_unicode):
# return the value corresponding to a key in the input dict
space = self.space
if self.w_valuedict is None:
- raise OperationError(space.w_TypeError,
- space.wrap("format requires a mapping"))
+ raise oefmt(space.w_TypeError, "format requires a mapping")
w_key = space.wrap(key)
return space.getitem(self.w_valuedict, w_key)
@@ -347,9 +340,9 @@ def make_formatter_subclass(do_unicode):
s = space.str_w(w_s)
else:
s = c
- msg = "unsupported format character '%s' (0x%x) at index %d" % (
- s, ord(c), self.fmtpos - 1)
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "unsupported format character '%s' (%s) at index %d",
+ s, hex(ord(c)), self.fmtpos - 1)
def std_wp(self, r):
length = len(r)
@@ -434,9 +427,8 @@ def make_formatter_subclass(do_unicode):
space = self.space
w_impl = space.lookup(w_value, '__str__')
if w_impl is None:
- raise OperationError(space.w_TypeError,
- space.wrap("operand does not support "
- "unary str"))
+ raise oefmt(space.w_TypeError,
+ "operand does not support unary str")
w_result = space.get_and_call_function(w_impl, w_value)
if space.isinstance_w(w_result,
space.w_unicode):
@@ -469,16 +461,14 @@ def make_formatter_subclass(do_unicode):
if space.isinstance_w(w_value, space.w_str):
s = space.str_w(w_value)
if len(s) != 1:
- raise OperationError(space.w_TypeError,
- space.wrap("%c requires int or char"))
+ raise oefmt(space.w_TypeError, "%c requires int or char")
self.std_wp(s)
elif space.isinstance_w(w_value, space.w_unicode):
if not do_unicode:
raise NeedUnicodeFormattingError
ustr = space.unicode_w(w_value)
if len(ustr) != 1:
- raise OperationError(space.w_TypeError,
- space.wrap("%c requires int or unichar"))
+ raise oefmt(space.w_TypeError, "%c requires int or unichar")
self.std_wp(ustr)
else:
n = space.int_w(w_value)
@@ -486,15 +476,15 @@ def make_formatter_subclass(do_unicode):
try:
c = unichr(n)
except ValueError:
- raise OperationError(space.w_OverflowError,
- space.wrap("unicode character code out of range"))
+ raise oefmt(space.w_OverflowError,
+ "unicode character code out of range")
self.std_wp(c)
else:
try:
s = chr(n)
- except ValueError: # chr(out-of-range)
- raise OperationError(space.w_OverflowError,
- space.wrap("character code not in range(256)"))
+ except ValueError:
+ raise oefmt(space.w_OverflowError,
+ "character code not in range(256)")
self.std_wp(s)
return StringFormatter
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
index 5d13ce342f..abe04771ea 100644
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -566,8 +566,7 @@ class W_ListObject(W_Root):
index = space.getindex_w(w_index, space.w_IndexError, "list index")
return self.getitem(index)
except IndexError:
- raise OperationError(space.w_IndexError,
- space.wrap("list index out of range"))
+ raise oefmt(space.w_IndexError, "list index out of range")
def descr_getslice(self, space, w_start, w_stop):
length = self.length()
@@ -594,8 +593,7 @@ class W_ListObject(W_Root):
try:
self.setitem(idx, w_any)
except IndexError:
- raise OperationError(space.w_IndexError,
- space.wrap("list index out of range"))
+ raise oefmt(space.w_IndexError, "list index out of range")
def descr_setslice(self, space, w_start, w_stop, w_iterable):
length = self.length()
@@ -621,8 +619,7 @@ class W_ListObject(W_Root):
try:
self.pop(idx)
except IndexError:
- raise OperationError(space.w_IndexError,
- space.wrap("list index out of range"))
+ raise oefmt(space.w_IndexError, "list index out of range")
def descr_delslice(self, space, w_start, w_stop):
length = self.length()
@@ -662,8 +659,7 @@ class W_ListObject(W_Root):
index (default last)'''
length = self.length()
if length == 0:
- raise OperationError(space.w_IndexError,
- space.wrap("pop from empty list"))
+ raise oefmt(space.w_IndexError, "pop from empty list")
# clearly differentiate between list.pop() and list.pop(index)
if index == -1:
return self.pop_end() # cannot raise because list is not empty
@@ -672,8 +668,7 @@ class W_ListObject(W_Root):
try:
return self.pop(index)
except IndexError:
- raise OperationError(space.w_IndexError,
- space.wrap("pop index out of range"))
+ raise oefmt(space.w_IndexError, "pop index out of range")
def descr_remove(self, space, w_value):
'L.remove(value) -- remove first occurrence of value'
@@ -769,8 +764,7 @@ class W_ListObject(W_Root):
self.__init__(space, sorter.list)
if mucked:
- raise OperationError(space.w_ValueError,
- space.wrap("list modified during sort"))
+ raise oefmt(space.w_ValueError, "list modified during sort")
find_jmp = jit.JitDriver(greens = ['tp'], reds = 'auto', name = 'list.find')
@@ -1489,14 +1483,15 @@ class AbstractUnwrappedStrategy(object):
def setslice(self, w_list, start, step, slicelength, w_other):
assert slicelength >= 0
+ space = self.space
- if self is self.space.fromcache(ObjectListStrategy):
+ if self is space.fromcache(ObjectListStrategy):
w_other = w_other._temporarily_as_objects()
elif not self.list_is_correct_type(w_other) and w_other.length() != 0:
w_list.switch_to_object_strategy()
w_other_as_object = w_other._temporarily_as_objects()
assert (w_other_as_object.strategy is
- self.space.fromcache(ObjectListStrategy))
+ space.fromcache(ObjectListStrategy))
w_list.setslice(start, step, slicelength, w_other_as_object)
return
@@ -1522,7 +1517,7 @@ class AbstractUnwrappedStrategy(object):
assert start >= 0
del items[start:start + delta]
elif len2 != slicelength: # No resize for extended slices
- raise oefmt(self.space.w_ValueError,
+ raise oefmt(space.w_ValueError,
"attempt to assign sequence of size %d to extended "
"slice of size %d", len2, slicelength)
@@ -2120,8 +2115,8 @@ class CustomCompareSort(SimpleSort):
result = space.int_w(w_result)
except OperationError as e:
if e.match(space, space.w_TypeError):
- raise OperationError(space.w_TypeError,
- space.wrap("comparison function must return int"))
+ raise oefmt(space.w_TypeError,
+ "comparison function must return int")
raise
return result < 0
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
index bd9f62aacf..7ce4eb24ed 100644
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -563,12 +563,11 @@ def _obj_getdict(self, space):
@objectmodel.dont_inline
def _obj_setdict(self, space, w_dict):
- from pypy.interpreter.error import OperationError
+ from pypy.interpreter.error import oefmt
terminator = self._get_mapdict_map().terminator
assert isinstance(terminator, DictTerminator) or isinstance(terminator, DevolvedDictTerminator)
if not space.isinstance_w(w_dict, space.w_dict):
- raise OperationError(space.w_TypeError,
- space.wrap("setting dictionary to a non-dict"))
+ raise oefmt(space.w_TypeError, "setting dictionary to a non-dict")
assert isinstance(w_dict, W_DictMultiObject)
w_olddict = self.getdict(space)
assert isinstance(w_olddict, W_DictMultiObject)
diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
index 49ab1730a9..f1f00152b9 100644
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -63,8 +63,7 @@ def make_template_formatting_class():
else:
out = rstring.StringBuilder()
if not level:
- raise OperationError(space.w_ValueError,
- space.wrap("Recursion depth exceeded"))
+ raise oefmt(space.w_ValueError, "Recursion depth exceeded")
level -= 1
s = self.template
return self._do_build_string(start, end, level, out, s)
@@ -82,14 +81,12 @@ def make_template_formatting_class():
markup_follows = True
if c == "}":
if at_end or s[i] != "}":
- raise OperationError(space.w_ValueError,
- space.wrap("Single '}'"))
+ raise oefmt(space.w_ValueError, "Single '}'")
i += 1
markup_follows = False
if c == "{":
if at_end:
- raise OperationError(space.w_ValueError,
- space.wrap("Single '{'"))
+ raise oefmt(space.w_ValueError, "Single '{'")
if s[i] == "{":
i += 1
markup_follows = False
@@ -121,8 +118,7 @@ def make_template_formatting_class():
break
i += 1
if nested:
- raise OperationError(space.w_ValueError,
- space.wrap("Unmatched '{'"))
+ raise oefmt(space.w_ValueError, "Unmatched '{'")
rendered = self._render_field(field_start, i, recursive, level)
out.append(rendered)
i += 1
@@ -144,16 +140,15 @@ def make_template_formatting_class():
if c == "!":
i += 1
if i == end:
- w_msg = self.space.wrap("expected conversion")
- raise OperationError(self.space.w_ValueError, w_msg)
+ raise oefmt(self.space.w_ValueError,
+ "expected conversion")
conversion = s[i]
i += 1
if i < end:
if s[i] != ':':
- w_msg = self.space.wrap("expected ':' after"
- " format specifier")
- raise OperationError(self.space.w_ValueError,
- w_msg)
+ raise oefmt(self.space.w_ValueError,
+ "expected ':' after format "
+ "specifier")
i += 1
else:
conversion = None
@@ -189,13 +184,12 @@ def make_template_formatting_class():
if use_numeric:
if self.auto_numbering_state == ANS_MANUAL:
if empty:
- msg = "switching from manual to automatic numbering"
- raise OperationError(space.w_ValueError,
- space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "switching from manual to automatic "
+ "numbering")
elif not empty:
- msg = "switching from automatic to manual numbering"
- raise OperationError(space.w_ValueError,
- space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "switching from automatic to manual numbering")
if empty:
index = self.auto_numbering
self.auto_numbering += 1
@@ -217,8 +211,7 @@ def make_template_formatting_class():
try:
w_arg = self.args[index]
except IndexError:
- w_msg = space.wrap("index out of range")
- raise OperationError(space.w_IndexError, w_msg)
+ raise oefmt(space.w_IndexError, "out of range")
return self._resolve_lookups(w_arg, name, i, end)
@jit.unroll_safe
@@ -237,8 +230,8 @@ def make_template_formatting_class():
break
i += 1
if start == i:
- w_msg = space.wrap("Empty attribute in format string")
- raise OperationError(space.w_ValueError, w_msg)
+ raise oefmt(space.w_ValueError,
+ "Empty attribute in format string")
w_attr = space.wrap(name[start:i])
if w_obj is not None:
w_obj = space.getattr(w_obj, w_attr)
@@ -256,8 +249,7 @@ def make_template_formatting_class():
break
i += 1
if not got_bracket:
- raise OperationError(space.w_ValueError,
- space.wrap("Missing ']'"))
+ raise oefmt(space.w_ValueError, "Missing ']'")
index, reached = _parse_int(self.space, name, start, i)
if index != -1 and reached == i:
w_item = space.wrap(index)
@@ -270,8 +262,8 @@ def make_template_formatting_class():
self.parser_list_w.append(space.newtuple([
space.w_False, w_item]))
else:
- msg = "Only '[' and '.' may follow ']'"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "Only '[' and '.' may follow ']'")
return w_obj
def formatter_field_name_split(self):
@@ -311,8 +303,7 @@ def make_template_formatting_class():
return space.call_function(space.w_unicode, w_obj)
return space.str(w_obj)
else:
- raise OperationError(self.space.w_ValueError,
- self.space.wrap("invalid conversion"))
+ raise oefmt(space.w_ValueError, "invalid conversion")
def _render_field(self, start, end, recursive, level):
name, conversion, spec_start = self._parse_field(start, end)
@@ -471,19 +462,17 @@ def make_formatting_class():
i += 1
self._precision, i = _parse_int(self.space, spec, i, length)
if self._precision == -1:
- raise OperationError(space.w_ValueError,
- space.wrap("no precision given"))
+ raise oefmt(space.w_ValueError, "no precision given")
if length - i > 1:
- raise OperationError(space.w_ValueError,
- space.wrap("invalid format spec"))
+ raise oefmt(space.w_ValueError, "invalid format spec")
if length - i == 1:
presentation_type = spec[i]
if self.is_unicode:
try:
the_type = spec[i].encode("ascii")[0]
except UnicodeEncodeError:
- raise OperationError(space.w_ValueError,
- space.wrap("invalid presentation type"))
+ raise oefmt(space.w_ValueError,
+ "invalid presentation type")
else:
the_type = presentation_type
i += 1
@@ -502,8 +491,7 @@ def make_formatting_class():
# ok
pass
else:
- raise OperationError(space.w_ValueError,
- space.wrap("invalid type with ','"))
+ raise oefmt(space.w_ValueError, "invalid type with ','")
return False
def _calc_padding(self, string, length):
@@ -546,9 +534,8 @@ def make_formatting_class():
return rstring.StringBuilder()
def _unknown_presentation(self, tp):
- msg = "unknown presentation for %s: '%s'"
- w_msg = self.space.wrap(msg % (tp, self._type))
- raise OperationError(self.space.w_ValueError, w_msg)
+ raise oefmt(self.space.w_ValueError,
+ "unknown presentation for %s: '%s'", tp, self._type)
def format_string(self, string):
space = self.space
@@ -557,14 +544,16 @@ def make_formatting_class():
if self._type != "s":
self._unknown_presentation("string")
if self._sign != "\0":
- msg = "Sign not allowed in string format specifier"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "Sign not allowed in string format specifier")
if self._alternate:
- msg = "Alternate form (#) not allowed in string format specifier"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "Alternate form (#) not allowed in string format "
+ "specifier")
if self._align == "=":
- msg = "'=' alignment not allowed in string format specifier"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "'=' alignment not allowed in string format "
+ "specifier")
length = len(string)
precision = self._precision
if precision != -1 and length >= precision:
@@ -762,14 +751,14 @@ def make_formatting_class():
def _format_int_or_long(self, w_num, kind):
space = self.space
if self._precision != -1:
- msg = "precision not allowed in integer type"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "precision not allowed in integer type")
sign_char = "\0"
tp = self._type
if tp == "c":
if self._sign != "\0":
- msg = "sign not allowed with 'c' presentation type"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "sign not allowed with 'c' presentation type")
value = space.int_w(w_num)
if self.is_unicode:
result = runicode.UNICHR(value)
@@ -920,8 +909,8 @@ def make_formatting_class():
flags = 0
default_precision = 6
if self._alternate:
- msg = "Alternate form (#) not allowed in float formats"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "Alternate form (#) not allowed in float formats")
tp = self._type
self._get_locale(tp)
if tp == "\0":
@@ -989,18 +978,19 @@ def make_formatting_class():
default_precision = 6
if self._align == "=":
# '=' alignment is invalid
- msg = ("'=' alignment flag is not allowed in"
- " complex format specifier")
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ raise oefmt(space.w_ValueError,
+ "'=' alignment flag is not allowed in complex "
+ "format specifier")
if self._fill_char == "0":
- #zero padding is invalid
- msg = "Zero padding is not allowed in complex format specifier"
- raise OperationError(space.w_ValueError, space.wrap(msg))
+ # zero padding is invalid
+ raise oefmt(space.w_ValueError,
+ "Zero padding is not allowed in complex format "
+ "specifier")
if self._alternate:
- #alternate is invalid
- msg = "Alternate form (#) not allowed in complex format specifier"
- raise OperationError(space.w_ValueError,
- space.wrap(msg))
+ # alternate is invalid
+ raise oefmt(space.w_ValueError,
+ "Alternate form (#) not allowed in complex format "
+ "specifier")
skip_re = 0
add_parens = 0
if tp == "\0":
diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py
index ecfa306929..70a0d7928f 100644
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -198,8 +198,7 @@ def descr___format__(space, w_obj, w_format_spec):
elif space.isinstance_w(w_format_spec, space.w_str):
w_as_str = space.str(w_obj)
else:
- msg = "format_spec must be a string"
- raise OperationError(space.w_TypeError, space.wrap(msg))
+ raise oefmt(space.w_TypeError, "format_spec must be a string")
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)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
index 49f2a7b99e..7e4e38c678 100644
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -374,8 +374,8 @@ class StdObjSpace(ObjSpace):
# one is not
def _wrap_expected_length(self, expected, got):
- return OperationError(self.w_ValueError,
- self.wrap("expected length %d, got %d" % (expected, got)))
+ return oefmt(self.w_ValueError,
+ "expected length %d, got %d", expected, got)
def unpackiterable(self, w_obj, expected_length=-1):
if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
@@ -506,8 +506,7 @@ class StdObjSpace(ObjSpace):
w_tup = self.call_function(w_indices, w_length)
l_w = self.unpackiterable(w_tup)
if not len(l_w) == 3:
- raise OperationError(self.w_ValueError,
- self.wrap("Expected tuple of length 3"))
+ raise oefmt(self.w_ValueError, "Expected tuple of length 3")
return self.int_w(l_w[0]), self.int_w(l_w[1]), self.int_w(l_w[2])
_DescrOperation_is_true = is_true
@@ -613,13 +612,12 @@ class StdObjSpace(ObjSpace):
def _type_issubtype(self, w_sub, w_type):
if isinstance(w_sub, W_TypeObject) and isinstance(w_type, W_TypeObject):
return self.wrap(w_sub.issubtype(w_type))
- raise OperationError(self.w_TypeError, self.wrap("need type objects"))
+ raise oefmt(self.w_TypeError, "need type objects")
@specialize.arg_or_var(2)
def _type_isinstance(self, w_inst, w_type):
if not isinstance(w_type, W_TypeObject):
- raise OperationError(self.w_TypeError,
- self.wrap("need type object"))
+ raise oefmt(self.w_TypeError, "need type object")
if is_annotation_constant(w_type):
cls = self._get_interplevel_cls(w_type)
if cls is not None:
diff --git a/pypy/objspace/std/proxyobject.py b/pypy/objspace/std/proxyobject.py
index 15f7819723..2522e291ed 100644
--- a/pypy/objspace/std/proxyobject.py
+++ b/pypy/objspace/std/proxyobject.py
@@ -1,7 +1,7 @@
""" transparent list implementation
"""
from pypy.interpreter import baseobjspace
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
def transparent_class(name, BaseCls):
@@ -20,8 +20,9 @@ def transparent_class(name, BaseCls):
return self.w_type
def setclass(self, space, w_subtype):
- raise OperationError(space.w_TypeError,
- space.wrap("You cannot override __class__ for transparent proxies"))
+ raise oefmt(space.w_TypeError,
+ "You cannot override __class__ for transparent "
+ "proxies")
def getdictvalue(self, space, attr):
try:
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
index 2aaef42bc6..43c3310c69 100644
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -1,6 +1,6 @@
from pypy.interpreter import gateway
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.signature import Signature
from pypy.interpreter.typedef import TypeDef
from pypy.objspace.std.bytesobject import W_BytesObject
@@ -173,8 +173,7 @@ class W_BaseSetObject(W_Root):
def descr_cmp(self, space, w_other):
if space.is_w(space.type(self), space.type(w_other)):
# hack hack until we get the expected result
- raise OperationError(space.w_TypeError,
- space.wrap('cannot compare sets using cmp()'))
+ raise oefmt(space.w_TypeError, "cannot compare sets using cmp()")
else:
return space.w_NotImplemented
@@ -840,8 +839,7 @@ class EmptySetStrategy(SetStrategy):
return EmptyIteratorImplementation(self.space, self, w_set)
def popitem(self, w_set):
- raise OperationError(self.space.w_KeyError,
- self.space.wrap('pop from an empty set'))
+ raise oefmt(self.space.w_KeyError, "pop from an empty set")
class AbstractUnwrappedSetStrategy(object):
@@ -1198,8 +1196,7 @@ class AbstractUnwrappedSetStrategy(object):
result = storage.popitem()
except KeyError:
# strategy may still be the same even if dict is empty
- raise OperationError(self.space.w_KeyError,
- self.space.wrap('pop from an empty set'))
+ raise oefmt(self.space.w_KeyError, "pop from an empty set")
return self.wrap(result[0])
@@ -1421,8 +1418,8 @@ class IteratorImplementation(object):
return None
if self.len != self.setimplementation.length():
self.len = -1 # Make this error state sticky
- raise OperationError(self.space.w_RuntimeError,
- self.space.wrap("set changed size during iteration"))
+ raise oefmt(self.space.w_RuntimeError,
+ "set changed size during iteration")
# look for the next entry
if self.pos < self.len:
result = self.next_entry()
@@ -1435,8 +1432,8 @@ class IteratorImplementation(object):
# We try to explicitly look it up in the set.
if not self.setimplementation.has_key(result):
self.len = -1 # Make this error state sticky
- raise OperationError(self.space.w_RuntimeError,
- self.space.wrap("dictionary changed during iteration"))
+ raise oefmt(self.space.w_RuntimeError,
+ "dictionary changed during iteration")
return result
# no more entries
self.setimplementation = None
diff --git a/pypy/objspace/std/sliceobject.py b/pypy/objspace/std/sliceobject.py
index bf5f766edd..14abecdfe4 100644
--- a/pypy/objspace/std/sliceobject.py
+++ b/pypy/objspace/std/sliceobject.py
@@ -3,7 +3,7 @@
import sys
from pypy.interpreter import gateway
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import GetSetProperty, TypeDef
from rpython.rlib.objectmodel import specialize
from rpython.rlib import jit
@@ -29,8 +29,7 @@ class W_SliceObject(W_Root):
else:
step = _eval_slice_index(space, w_slice.w_step)
if step == 0:
- raise OperationError(space.w_ValueError,
- space.wrap("slice step cannot be zero"))
+ raise oefmt(space.w_ValueError, "slice step cannot be zero")
if space.is_w(w_slice.w_start, space.w_None):
if step < 0:
start = length - 1
@@ -98,11 +97,9 @@ class W_SliceObject(W_Root):
elif len(args_w) == 3:
w_start, w_stop, w_step = args_w
elif len(args_w) > 3:
- raise OperationError(space.w_TypeError,
- space.wrap("slice() takes at most 3 arguments"))
+ raise oefmt(space.w_TypeError, "slice() takes at most 3 arguments")
else:
- raise OperationError(space.w_TypeError,
- space.wrap("slice() takes at least 1 argument"))
+ raise oefmt(space.w_TypeError, "slice() takes at least 1 argument")
w_obj = space.allocate_instance(W_SliceObject, w_slicetype)
W_SliceObject.__init__(w_obj, w_start, w_stop, w_step)
return w_obj
@@ -166,8 +163,7 @@ def slicewprop(name):
def fget(space, w_obj):
from pypy.objspace.std.sliceobject import W_SliceObject
if not isinstance(w_obj, W_SliceObject):
- raise OperationError(space.w_TypeError,
- space.wrap("descriptor is for 'slice'"))
+ raise oefmt(space.w_TypeError, "descriptor is for 'slice'")
return getattr(w_obj, name)
return GetSetProperty(fget)
@@ -200,9 +196,9 @@ def _eval_slice_index(space, w_int):
except OperationError as err:
if not err.match(space, space.w_TypeError):
raise
- raise OperationError(space.w_TypeError,
- space.wrap("slice indices must be integers or "
- "None or have an __index__ method"))
+ raise oefmt(space.w_TypeError,
+ "slice indices must be integers or None or have an "
+ "__index__ method")
def adapt_lower_bound(space, size, w_index):
index = _eval_slice_index(space, w_index)
diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
index a5b6f37d7e..72ab4aafa8 100644
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import oefmt
from pypy.objspace.std.tupleobject import W_AbstractTupleObject
from pypy.objspace.std.util import negate
from rpython.rlib.objectmodel import compute_hash, specialize
@@ -117,8 +117,7 @@ def make_specialised_class(typetuple):
if typetuple[i] != object:
value = space.wrap(value)
return value
- raise OperationError(space.w_IndexError,
- space.wrap("tuple index out of range"))
+ raise oefmt(space.w_IndexError, "tuple index out of range")
cls.__name__ = ('W_SpecialisedTupleObject_' +
''.join([t.__name__[0] for t in typetuple]))
@@ -181,8 +180,7 @@ def _build_zipped_unspec(space, w_list1, w_list2):
def specialized_zip_2_lists(space, w_list1, w_list2):
from pypy.objspace.std.listobject import W_ListObject
if type(w_list1) is not W_ListObject or type(w_list2) is not W_ListObject:
- raise OperationError(space.w_TypeError,
- space.wrap("expected two exact lists"))
+ raise oefmt(space.w_TypeError, "expected two exact lists")
if space.config.objspace.std.withspecialisedtuple:
intlist1 = w_list1.getitems_int()
diff --git a/pypy/objspace/std/transparent.py b/pypy/objspace/std/transparent.py
index e63a3b5483..418e132220 100644
--- a/pypy/objspace/std/transparent.py
+++ b/pypy/objspace/std/transparent.py
@@ -49,7 +49,7 @@ def proxy(space, w_type, w_controller):
Return something that looks like it is of type typ. Its behaviour is
completely controlled by the controller."""
if not space.is_true(space.callable(w_controller)):
- raise OperationError(space.w_TypeError, space.wrap("controller should be function"))
+ raise oefmt(space.w_TypeError, "controller should be function")
if isinstance(w_type, W_TypeObject):
if space.is_true(space.issubtype(w_type, space.gettypeobject(Function.typedef))):
@@ -65,7 +65,7 @@ completely controlled by the controller."""
if w_type.layout.typedef is space.w_object.layout.typedef:
return W_Transparent(space, w_type, w_controller)
else:
- raise OperationError(space.w_TypeError, space.wrap("type expected as first argument"))
+ raise oefmt(space.w_TypeError, "type expected as first argument")
w_lookup = w_type
for k, v in type_cache.cache:
if w_lookup == k:
diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
index f55cada195..c6877db38a 100644
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -3,7 +3,7 @@
import sys
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import (
WrappedDefault, interp2app, interpindirect2app, unwrap_spec)
from pypy.interpreter.typedef import TypeDef
@@ -213,8 +213,7 @@ class W_AbstractTupleObject(W_Root):
w_item = self.tolist()[i]
if space.eq_w(w_item, w_obj):
return space.wrap(i)
- raise OperationError(space.w_ValueError,
- space.wrap("tuple.index(x): x not in tuple"))
+ raise oefmt(space.w_ValueError, "tuple.index(x): x not in tuple")
W_AbstractTupleObject.typedef = TypeDef(
"tuple",
@@ -326,8 +325,7 @@ class W_TupleObject(W_AbstractTupleObject):
try:
return self.wrappeditems[index]
except IndexError:
- raise OperationError(space.w_IndexError,
- space.wrap("tuple index out of range"))
+ raise oefmt(space.w_IndexError, "tuple index out of range")
def wraptuple(space, list_w):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
index 9c567b08ae..a72ede8a44 100644
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -1,7 +1,7 @@
import weakref
from pypy.interpreter import gateway
from pypy.interpreter.baseobjspace import W_Root, SpaceCache
-from pypy.interpreter.error import oefmt, OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.function import Function, StaticMethod
from pypy.interpreter.typedef import weakref_descr, GetSetProperty,\
descr_get_dict, dict_descr, Member, TypeDef
@@ -1240,8 +1240,8 @@ def mro_error(space, orderlists):
cycle.append(candidate)
cycle.reverse()
names = [cls.getname(space) for cls in cycle]
- raise OperationError(space.w_TypeError, space.wrap(
- "cycle among base classes: " + ' < '.join(names)))
+ raise oefmt(space.w_TypeError,
+ "cycle among base classes: %s", ' < '.join(names))
class TypeCache(SpaceCache):
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
index 16aafebc7b..24d8910099 100644
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -73,8 +73,8 @@ class W_UnicodeObject(W_Root):
return StringBuffer(builder.build())
def writebuf_w(self, space):
- raise OperationError(space.w_TypeError, space.wrap(
- "cannot use unicode as modifiable buffer"))
+ raise oefmt(space.w_TypeError,
+ "cannot use unicode as modifiable buffer")
charbuf_w = str_w
diff --git a/pypy/tool/pytest/appsupport.py b/pypy/tool/pytest/appsupport.py
index fd6f0f45ec..6f1edee57f 100644
--- a/pypy/tool/pytest/appsupport.py
+++ b/pypy/tool/pytest/appsupport.py
@@ -2,7 +2,7 @@ from inspect import CO_VARARGS, CO_VARKEYWORDS
import py
from pypy.interpreter import gateway, pycode
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
try:
from _pytest.assertion.newinterpret import interpret
@@ -232,9 +232,8 @@ def pypyraises(space, w_ExpectedException, w_expr, __args__):
args_w, kwds_w = __args__.unpack()
if space.isinstance_w(w_expr, space.w_str):
if args_w:
- raise OperationError(space.w_TypeError,
- space.wrap("raises() takes no argument "
- "after a string expression"))
+ raise oefmt(space.w_TypeError,
+ "raises() takes no argument after a string expression")
expr = space.unwrap(w_expr)
source = py.code.Source(expr)
frame = space.getexecutioncontext().gettopframe()
@@ -264,8 +263,7 @@ def pypyraises(space, w_ExpectedException, w_expr, __args__):
if e.match(space, w_ExpectedException):
return _exc_info(space, e)
raise
- raise OperationError(space.w_AssertionError,
- space.wrap("DID NOT RAISE"))
+ raise oefmt(space.w_AssertionError, "DID NOT RAISE")
app_raises = gateway.interp2app_temp(pypyraises)