Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r84156:35dcdbf2fb5d Date: 2016-05-02 17:27 -0700 http://bitbucket.org/pypy/pypy/changeset/35dcdbf2fb5d/
Log: merge default (oefmt pypy/{objspace,tool}/) diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -294,8 +294,7 @@ 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): @@ -370,8 +369,7 @@ 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__') @@ -475,8 +473,7 @@ 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/dictproxyobject.py b/pypy/objspace/std/dictproxyobject.py --- a/pypy/objspace/std/dictproxyobject.py +++ b/pypy/objspace/std/dictproxyobject.py @@ -63,7 +63,8 @@ if space.is_w(space.type(w_key), space.w_unicode): 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 --- a/pypy/objspace/std/formatting.py +++ b/pypy/objspace/std/formatting.py @@ -28,27 +28,24 @@ 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=''): # 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: @@ -164,9 +161,7 @@ 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. @@ -182,8 +177,7 @@ 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: @@ -198,8 +192,7 @@ # 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) @@ -341,9 +334,9 @@ 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) @@ -428,9 +421,8 @@ 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): @@ -468,16 +460,14 @@ 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) @@ -485,15 +475,15 @@ 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 --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -565,8 +565,7 @@ 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_setitem(self, space, w_index, w_any): if isinstance(w_index, W_SliceObject): @@ -584,8 +583,7 @@ 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_delitem(self, space, w_idx): if isinstance(w_idx, W_SliceObject): @@ -600,8 +598,7 @@ 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_reversed(self, space): 'L.__reversed__() -- return a reverse iterator over the list' @@ -636,8 +633,7 @@ 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 @@ -646,8 +642,7 @@ 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_clear(self, space): '''L.clear() -- remove all items''' @@ -748,8 +743,7 @@ 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') @@ -1468,14 +1462,15 @@ 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 @@ -1501,7 +1496,7 @@ 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) @@ -2099,8 +2094,8 @@ 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 --- a/pypy/objspace/std/mapdict.py +++ b/pypy/objspace/std/mapdict.py @@ -561,12 +561,11 @@ @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 --- a/pypy/objspace/std/newformat.py +++ b/pypy/objspace/std/newformat.py @@ -64,8 +64,7 @@ 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) @@ -83,14 +82,12 @@ 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 @@ -122,8 +119,7 @@ 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 @@ -145,16 +141,15 @@ 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 @@ -190,13 +185,12 @@ 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 @@ -219,8 +213,7 @@ 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 @@ -239,8 +232,8 @@ 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) @@ -258,8 +251,7 @@ 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) @@ -272,8 +264,8 @@ 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): @@ -316,8 +308,7 @@ from pypy.objspace.std.unicodeobject import ascii_from_object return ascii_from_object(space, 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) @@ -476,19 +467,17 @@ 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 @@ -507,8 +496,7 @@ # 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): @@ -551,9 +539,8 @@ 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, w_string): space = self.space @@ -565,14 +552,16 @@ 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: @@ -770,14 +759,14 @@ 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) @@ -1000,13 +989,14 @@ 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: flags |= rfloat.DTSF_ALT diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py --- a/pypy/objspace/std/objectobject.py +++ b/pypy/objspace/std/objectobject.py @@ -195,8 +195,7 @@ 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_DeprecationWarning) diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -532,8 +532,7 @@ 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 @@ -646,13 +645,12 @@ 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 --- 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 @@ 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 --- 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 @@ -820,8 +820,7 @@ 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): @@ -1178,8 +1177,7 @@ 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]) @@ -1401,8 +1399,8 @@ 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() @@ -1415,8 +1413,8 @@ # 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 --- 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 @@ 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 @@ 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 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 @@ 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 --- 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 specialize @@ -123,8 +123,7 @@ 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])) @@ -187,8 +186,7 @@ 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 --- a/pypy/objspace/std/transparent.py +++ b/pypy/objspace/std/transparent.py @@ -49,7 +49,7 @@ 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 @@ 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 --- 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 @@ -210,8 +210,7 @@ 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", @@ -322,8 +321,7 @@ 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 --- 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, ClassMethod, FunctionWithFixedCode) from pypy.interpreter.typedef import weakref_descr, GetSetProperty,\ diff --git a/pypy/tool/pytest/appsupport.py b/pypy/tool/pytest/appsupport.py --- a/pypy/tool/pytest/appsupport.py +++ b/pypy/tool/pytest/appsupport.py @@ -2,7 +2,7 @@ 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 @@ -236,9 +236,8 @@ args_w, kwds_w = __args__.unpack() if space.isinstance_w(w_expr, space.w_unicode): 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() @@ -268,8 +267,7 @@ 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) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit