[pypy-commit] pypy oefmt: oefmt pypy/module/_*

pjenvey pypy.commits at gmail.com
Mon May 2 02:33:03 EDT 2016


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: oefmt
Changeset: r84120:18b5bfbd3dfb
Date: 2016-05-01 22:34 -0700
http://bitbucket.org/pypy/pypy/changeset/18b5bfbd3dfb/

Log:	oefmt pypy/module/_*

diff too long, truncating to 2000 out of 2996 lines

diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -3,7 +3,7 @@
 """
 
 from pypy.interpreter.pycode import PyCode
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.astcompiler import consts, ast
 from pypy.interpreter.gateway import unwrap_spec
 
@@ -26,8 +26,7 @@
     if flags & ~(ec.compiler.compiler_flags | consts.PyCF_ONLY_AST |
                  consts.PyCF_DONT_IMPLY_DEDENT | consts.PyCF_SOURCE_IS_UTF8 |
                  consts.PyCF_ACCEPT_NULL_BYTES):
-        raise OperationError(space.w_ValueError,
-                             space.wrap("compile() unrecognized flags"))
+        raise oefmt(space.w_ValueError, "compile() unrecognized flags")
 
     if not dont_inherit:
         caller = ec.gettopframe_nohidden()
@@ -35,9 +34,8 @@
             flags |= ec.compiler.getcodeflags(caller.getcode())
 
     if mode not in ('exec', 'eval', 'single'):
-        raise OperationError(space.w_ValueError,
-                             space.wrap("compile() arg 3 must be 'exec' "
-                                        "or 'eval' or 'single'"))
+        raise oefmt(space.w_ValueError,
+                    "compile() arg 3 must be 'exec' or 'eval' or 'single'")
 
     if space.isinstance_w(w_source, space.gettypeobject(ast.W_AST.typedef)):
         ast_node = ast.mod.from_object(space, w_source)
@@ -55,8 +53,8 @@
 
     if not (flags & consts.PyCF_ACCEPT_NULL_BYTES):
         if '\x00' in source:
-            raise OperationError(space.w_TypeError, space.wrap(
-                "compile() expected string without null bytes"))
+            raise oefmt(space.w_TypeError,
+                        "compile() expected string without null bytes")
 
     if flags & consts.PyCF_ONLY_AST:
         node = ec.compiler.compile_to_ast(source, filename, mode, flags)
@@ -73,8 +71,6 @@
 are dictionaries, defaulting to the current current globals and locals.
 If only globals is given, locals defaults to it.
 """
-    w = space.wrap
-
     if (space.isinstance_w(w_code, space.w_str) or
         space.isinstance_w(w_code, space.w_unicode)):
         w_code = compile(space,
@@ -83,8 +79,8 @@
                          "<string>", "eval")
 
     if not isinstance(w_code, PyCode):
-        raise OperationError(space.w_TypeError,
-              w('eval() arg 1 must be a string or code object'))
+        raise oefmt(space.w_TypeError,
+                    "eval() arg 1 must be a string or code object")
 
     if space.is_none(w_globals):
         caller = space.getexecutioncontext().gettopframe_nohidden()
diff --git a/pypy/module/__builtin__/descriptor.py b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -1,5 +1,5 @@
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.function import StaticMethod, ClassMethod
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from pypy.interpreter.typedef import (TypeDef, interp_attrproperty_w,
@@ -67,9 +67,9 @@
                     raise
                 w_type = w_objtype
             if not space.is_true(space.issubtype(w_type, w_starttype)):
-                raise OperationError(space.w_TypeError,
-                    space.wrap("super(type, obj): "
-                               "obj must be an instance or subtype of type"))
+                raise oefmt(space.w_TypeError,
+                            "super(type, obj): obj must be an instance or "
+                            "subtype of type")
     # XXX the details of how allocate_instance() should be used are not
     # really well defined
     w_result = space.allocate_instance(W_Super, w_subtype)
@@ -126,21 +126,18 @@
         if space.is_w(w_obj, space.w_None):
             return space.wrap(self)
         if space.is_w(self.w_fget, space.w_None):
-            raise OperationError(space.w_AttributeError, space.wrap(
-                "unreadable attribute"))
+            raise oefmt(space.w_AttributeError, "unreadable attribute")
         return space.call_function(self.w_fget, w_obj)
 
     def set(self, space, w_obj, w_value):
         if space.is_w(self.w_fset, space.w_None):
-            raise OperationError(space.w_AttributeError, space.wrap(
-                "can't set attribute"))
+            raise oefmt(space.w_AttributeError, "can't set attribute")
         space.call_function(self.w_fset, w_obj, w_value)
         return space.w_None
 
     def delete(self, space, w_obj):
         if space.is_w(self.w_fdel, space.w_None):
-            raise OperationError(space.w_AttributeError, space.wrap(
-                "can't delete attribute"))
+            raise oefmt(space.w_AttributeError, "can't delete attribute")
         space.call_function(self.w_fdel, w_obj)
         return space.w_None
 
diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -5,7 +5,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 interp2app, unwrap_spec, WrappedDefault
 from pypy.interpreter.typedef import TypeDef
 from rpython.rlib import jit, rarithmetic
@@ -32,8 +32,7 @@
     # hi-lo-1 = M-(-M-1)-1 = 2*M.  Therefore unsigned long has enough
     # precision to compute the RHS exactly.
     if step == 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("step argument must not be zero"))
+        raise oefmt(space.w_ValueError, "step argument must not be zero")
     elif step < 0:
         lo, hi, step = hi, lo, -step
     if lo < hi:
@@ -42,8 +41,7 @@
         diff = uhi - ulo - 1
         n = intmask(diff // r_uint(step) + 1)
         if n < 0:
-            raise OperationError(space.w_OverflowError,
-                                 space.wrap("result has too many items"))
+            raise oefmt(space.w_OverflowError, "result has too many items")
     else:
         n = 0
     return n
@@ -63,14 +61,14 @@
         w_stop = w_y
 
     if space.isinstance_w(w_stop, space.w_float):
-        raise OperationError(space.w_TypeError,
-            space.wrap("range() integer end argument expected, got float."))
+        raise oefmt(space.w_TypeError,
+                    "range() integer end argument expected, got float.")
     if space.isinstance_w(w_start, space.w_float):
-        raise OperationError(space.w_TypeError,
-            space.wrap("range() integer start argument expected, got float."))
+        raise oefmt(space.w_TypeError,
+                    "range() integer start argument expected, got float.")
     if space.isinstance_w(w_step, space.w_float):
-        raise OperationError(space.w_TypeError,
-            space.wrap("range() integer step argument expected, got float."))
+        raise oefmt(space.w_TypeError,
+                    "range() integer step argument expected, got float.")
 
     w_start = space.int(w_start)
     w_stop = space.int(w_stop)
@@ -112,8 +110,7 @@
     step = st = space.bigint_w(w_step)
 
     if not step.tobool():
-        raise OperationError(space.w_ValueError,
-                             space.wrap("step argument must not be zero"))
+        raise oefmt(space.w_ValueError, "step argument must not be zero")
     elif step.sign < 0:
         lo, hi, st = hi, lo, st.neg()
 
@@ -123,8 +120,7 @@
         try:
             howmany = n.toint()
         except OverflowError:
-            raise OperationError(space.w_OverflowError,
-                                 space.wrap("result has too many items"))
+            raise oefmt(space.w_OverflowError, "result has too many items")
     else:
         howmany = 0
 
@@ -155,16 +151,18 @@
         elif len(args_w):
             w_sequence = args_w[0]
         else:
-            msg = "%s() expects at least one argument" % (implementation_of,)
-            raise OperationError(space.w_TypeError, space.wrap(msg))
+            raise oefmt(space.w_TypeError,
+                        "%s() expects at least one argument",
+                        implementation_of)
         w_key = None
         kwds = args.keywords
         if kwds:
             if kwds[0] == "key" and len(kwds) == 1:
                 w_key = args.keywords_w[0]
             else:
-                msg = "%s() got unexpected keyword argument" % (implementation_of,)
-                raise OperationError(space.w_TypeError, space.wrap(msg))
+                raise oefmt(space.w_TypeError,
+                            "%s() got unexpected keyword argument",
+                            implementation_of)
 
         w_iter = space.iter(w_sequence)
         w_type = space.type(w_iter)
@@ -191,8 +189,7 @@
                 w_max_item = w_item
                 w_max_val = w_compare_with
         if w_max_item is None:
-            msg = "arg is an empty sequence"
-            raise OperationError(space.w_ValueError, space.wrap(msg))
+            raise oefmt(space.w_ValueError, "arg is an empty sequence")
         return w_max_item
     if unroll:
         min_max_impl = jit.unroll_safe(min_max_impl)
@@ -341,8 +338,8 @@
     def __init__(self, space, w_sequence):
         self.remaining = space.len_w(w_sequence) - 1
         if space.lookup(w_sequence, "__getitem__") is None:
-            msg = "reversed() argument must be a sequence"
-            raise OperationError(space.w_TypeError, space.wrap(msg))
+            raise oefmt(space.w_TypeError,
+                        "reversed() argument must be a sequence")
         self.w_sequence = w_sequence
 
     def descr___iter__(self, space):
@@ -439,8 +436,7 @@
             i += len
         if 0 <= i < len:
             return space.wrap(self.start + i * self.step)
-        raise OperationError(space.w_IndexError,
-                             space.wrap("xrange object index out of range"))
+        raise oefmt(space.w_IndexError, "xrange object index out of range")
 
     def descr_iter(self):
         if self.promote_step and self.step == 1:
diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -32,8 +32,7 @@
             if space.is_true(space.callable(w_metaclass)):
                 return space.call_function(w_metaclass, w_name,
                                            w_bases, w_dict)
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("base must be class"))
+            raise oefmt(space.w_TypeError, "base must be class")
 
     return W_ClassObject(space, w_name, bases_w, w_dict)
 
@@ -58,28 +57,23 @@
 
     def setdict(self, space, w_dict):
         if not space.isinstance_w(w_dict, space.w_dict):
-            raise OperationError(
-                space.w_TypeError,
-                space.wrap("__dict__ must be a dictionary object"))
+            raise oefmt(space.w_TypeError,
+                        "__dict__ must be a dictionary object")
         self.w_dict = w_dict
 
     def setname(self, space, w_newname):
         if not space.isinstance_w(w_newname, space.w_str):
-            raise OperationError(space.w_TypeError,
-                space.wrap("__name__ must be a string object")
-            )
+            raise oefmt(space.w_TypeError, "__name__ must be a string object")
         self.name = space.str_w(w_newname)
 
     def setbases(self, space, w_bases):
         if not space.isinstance_w(w_bases, space.w_tuple):
-            raise OperationError(space.w_TypeError,
-                space.wrap("__bases__ must be a tuple object")
-            )
+            raise oefmt(space.w_TypeError, "__bases__ must be a tuple object")
         bases_w = space.fixedview(w_bases)
         for w_base in bases_w:
             if not isinstance(w_base, W_ClassObject):
-                raise OperationError(space.w_TypeError,
-                                     space.wrap("__bases__ items must be classes"))
+                raise oefmt(space.w_TypeError,
+                            "__bases__ items must be classes")
         self.bases_w = bases_w
 
     def is_subclass_of(self, other):
@@ -207,13 +201,9 @@
     if w_init is not None:
         w_result = space.call_args(w_init, __args__)
         if not space.is_w(w_result, space.w_None):
-            raise OperationError(
-                space.w_TypeError,
-                space.wrap("__init__() should return None"))
+            raise oefmt(space.w_TypeError, "__init__() should return None")
     elif __args__.arguments_w or __args__.keywords:
-        raise OperationError(
-                space.w_TypeError,
-                space.wrap("this constructor takes no arguments"))
+        raise oefmt(space.w_TypeError, "this constructor takes no arguments")
     return w_inst
 
 W_ClassObject.typedef = TypeDef("classobj",
@@ -297,9 +287,7 @@
 def descr_instance_new(space, w_type, w_class, w_dict=None):
     # w_type is not used at all
     if not isinstance(w_class, W_ClassObject):
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("instance() first arg must be class"))
+        raise oefmt(space.w_TypeError, "instance() first arg must be class")
     w_result = w_class.instantiate(space)
     if not space.is_none(w_dict):
         w_result.setdict(space, w_dict)
@@ -318,9 +306,7 @@
 
     def set_oldstyle_class(self, space, w_class):
         if w_class is None or not isinstance(w_class, W_ClassObject):
-            raise OperationError(
-                space.w_TypeError,
-                space.wrap("__class__ must be set to a class"))
+            raise oefmt(space.w_TypeError, "__class__ must be set to a class")
         self.w_class = w_class
 
     def getattr_from_class(self, space, name):
@@ -453,13 +439,9 @@
         w_result = space.call_function(w_meth)
         if space.isinstance_w(w_result, space.w_int):
             if space.is_true(space.lt(w_result, space.wrap(0))):
-                raise OperationError(
-                    space.w_ValueError,
-                    space.wrap("__len__() should return >= 0"))
+                raise oefmt(space.w_ValueError, "__len__() should return >= 0")
             return w_result
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("__len__() should return an int"))
+        raise oefmt(space.w_TypeError, "__len__() should return an int")
 
     def descr_getitem(self, space, w_key):
         w_meth = self.getattr(space, '__getitem__')
@@ -479,9 +461,7 @@
             return space.call_function(w_meth)
         w_meth = self.getattr(space, '__getitem__', False)
         if w_meth is None:
-            raise OperationError(
-                space.w_TypeError,
-                space.wrap("iteration over non-sequence"))
+            raise oefmt(space.w_TypeError, "iteration over non-sequence")
         return space.newseqiter(self)
     #XXX do I really need a next method? the old implementation had one, but I
     # don't see the point
@@ -521,13 +501,10 @@
         w_result = space.call_function(w_func)
         if space.isinstance_w(w_result, space.w_int):
             if space.is_true(space.lt(w_result, space.wrap(0))):
-                raise OperationError(
-                    space.w_ValueError,
-                    space.wrap("__nonzero__() should return >= 0"))
+                raise oefmt(space.w_ValueError,
+                            "__nonzero__() should return >= 0")
             return w_result
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("__nonzero__() should return an int"))
+        raise oefmt(space.w_TypeError, "__nonzero__() should return an int")
 
     def descr_cmp(self, space, w_other): # do all the work here like CPython
         w_a, w_b = _coerce_helper(space, self, w_other)
@@ -544,9 +521,8 @@
                     res = space.int_w(w_res)
                 except OperationError, e:
                     if e.match(space, space.w_TypeError):
-                        raise OperationError(
-                            space.w_TypeError,
-                            space.wrap("__cmp__ must return int"))
+                        raise oefmt(space.w_TypeError,
+                                    "__cmp__ must return int")
                     raise
                 if res > 0:
                     return space.wrap(1)
@@ -563,9 +539,8 @@
                     res = space.int_w(w_res)
                 except OperationError, e:
                     if e.match(space, space.w_TypeError):
-                        raise OperationError(
-                            space.w_TypeError,
-                            space.wrap("__cmp__ must return int"))
+                        raise oefmt(space.w_TypeError,
+                                    "__cmp__ must return int")
                     raise
                 if res < 0:
                     return space.wrap(1)
@@ -580,16 +555,13 @@
             w_eq = self.getattr(space, '__eq__', False)
             w_cmp = self.getattr(space, '__cmp__', False)
             if w_eq is not None or w_cmp is not None:
-                raise OperationError(space.w_TypeError,
-                                     space.wrap("unhashable instance"))
+                raise oefmt(space.w_TypeError, "unhashable instance")
             else:
                 return space.wrap(compute_identity_hash(self))
         w_ret = space.call_function(w_func)
         if (not space.isinstance_w(w_ret, space.w_int) and
             not space.isinstance_w(w_ret, space.w_long)):
-            raise OperationError(
-                space.w_TypeError,
-                space.wrap("__hash__ must return int or long"))
+            raise oefmt(space.w_TypeError, "__hash__ must return int or long")
         return w_ret
 
     def descr_int(self, space):
@@ -603,9 +575,7 @@
             return space.int(w_truncated)
         except OperationError:
             # Raise a different error
-            raise OperationError(
-                space.w_TypeError,
-                space.wrap("__trunc__ returned non-Integral"))
+            raise oefmt(space.w_TypeError, "__trunc__ returned non-Integral")
 
     def descr_long(self, space):
         w_func = self.getattr(space, '__long__', False)
@@ -617,9 +587,8 @@
         w_func = self.getattr(space, '__index__', False)
         if w_func is not None:
             return space.call_function(w_func)
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("object cannot be interpreted as an index"))
+        raise oefmt(space.w_TypeError,
+                    "object cannot be interpreted as an index")
 
     def descr_contains(self, space, w_obj):
         w_func = self.getattr(space, '__contains__', False)
@@ -674,8 +643,7 @@
     def descr_next(self, space):
         w_func = self.getattr(space, 'next', False)
         if w_func is None:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("instance has no next() method"))
+            raise oefmt(space.w_TypeError, "instance has no next() method")
         return space.call_function(w_func)
 
     def descr_del(self, space):
diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -3,7 +3,7 @@
 """
 
 from pypy.interpreter import gateway
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
 from rpython.rlib.runicode import UNICHR
 from rpython.rlib.rfloat import isnan, isinf, round_double
@@ -19,8 +19,7 @@
     try:
         char = __builtin__.chr(space.int_w(w_ascii))
     except ValueError:  # chr(out-of-range)
-        raise OperationError(space.w_ValueError,
-                             space.wrap("character code not in range(256)"))
+        raise oefmt(space.w_ValueError, "character code not in range(256)")
     return space.wrap(char)
 
 @unwrap_spec(code=int)
@@ -30,8 +29,7 @@
     try:
         c = UNICHR(code)
     except ValueError:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("unichr() arg out of range"))
+        raise oefmt(space.w_ValueError, "unichr() arg out of range")
     return space.wrap(c)
 
 def len(space, w_obj):
@@ -151,8 +149,8 @@
     # finite x, and ndigits is not unreasonably large
     z = round_double(number, ndigits)
     if isinf(z):
-        raise OperationError(space.w_OverflowError,
-                             space.wrap("rounded value too large to represent"))
+        raise oefmt(space.w_OverflowError,
+                    "rounded value too large to represent")
     return space.wrap(z)
 
 # ____________________________________________________________
@@ -227,7 +225,7 @@
 same value."""
     if space.is_w(space.type(w_str), space.w_str):
         return space.new_interned_w_str(w_str)
-    raise OperationError(space.w_TypeError, space.wrap("intern() argument must be string."))
+    raise oefmt(space.w_TypeError, "intern() argument must be string.")
 
 def callable(space, w_object):
     """Check whether the object appears to be callable (i.e., some kind of
diff --git a/pypy/module/__pypy__/interp_builders.py b/pypy/module/__pypy__/interp_builders.py
--- a/pypy/module/__pypy__/interp_builders.py
+++ b/pypy/module/__pypy__/interp_builders.py
@@ -1,5 +1,5 @@
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef
 from rpython.rlib.rstring import UnicodeBuilder, StringBuilder
@@ -16,8 +16,8 @@
 
         def _check_done(self, space):
             if self.builder is None:
-                raise OperationError(space.w_ValueError, space.wrap(
-                        "Can't operate on a built builder"))
+                raise oefmt(space.w_ValueError,
+                            "Can't operate on a built builder")
 
         @unwrap_spec(size=int)
         def descr__new__(space, w_subtype, size=-1):
@@ -32,8 +32,7 @@
         def descr_append_slice(self, space, s, start, end):
             self._check_done(space)
             if not 0 <= start <= end <= len(s):
-                raise OperationError(space.w_ValueError, space.wrap(
-                        "bad start/stop"))
+                raise oefmt(space.w_ValueError, "bad start/stop")
             self.builder.append_slice(s, start, end)
 
         def descr_build(self, space):
@@ -44,8 +43,7 @@
 
         def descr_len(self, space):
             if self.builder is None:
-                raise OperationError(space.w_ValueError, space.wrap(
-                        "no length of built builder"))
+                raise oefmt(space.w_ValueError, "no length of built builder")
             return space.wrap(self.builder.getlength())
 
     W_Builder.__name__ = "W_%s" % name
diff --git a/pypy/module/__pypy__/interp_identitydict.py b/pypy/module/__pypy__/interp_identitydict.py
--- a/pypy/module/__pypy__/interp_identitydict.py
+++ b/pypy/module/__pypy__/interp_identitydict.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.baseobjspace import W_Root
@@ -35,9 +35,9 @@
             raise OperationError(space.w_KeyError, w_key)
 
     def descr_iter(self, space):
-        raise OperationError(space.w_TypeError,
-            space.wrap("'identity_dict' object does not support iteration; "
-                       "iterate over x.keys()"))
+        raise oefmt(space.w_TypeError,
+                    "'identity_dict' object does not support iteration; "
+                    "iterate over x.keys()")
 
     def get(self, space, w_key, w_default=None):
         if w_default is None:
diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
+from pypy.interpreter.error import oefmt, wrap_oserror
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.pycode import CodeHookCache
 from pypy.interpreter.pyframe import PyFrame
@@ -74,8 +74,8 @@
 def lookup_special(space, w_obj, meth):
     """Lookup up a special method on an object."""
     if space.is_oldstyle_instance(w_obj):
-        w_msg = space.wrap("this doesn't do what you want on old-style classes")
-        raise OperationError(space.w_TypeError, w_msg)
+        raise oefmt(space.w_TypeError,
+                    "this doesn't do what you want on old-style classes")
     w_descr = space.lookup(w_obj, meth)
     if w_descr is None:
         return space.w_None
@@ -97,8 +97,7 @@
     elif isinstance(w_obj, W_BaseSetObject):
         name = w_obj.strategy.__class__.__name__
     else:
-        raise OperationError(space.w_TypeError,
-                             space.wrap("expecting dict or list or set object"))
+        raise oefmt(space.w_TypeError, "expecting dict or list or set object")
     return space.wrap(name)
 
 
@@ -119,8 +118,7 @@
 @unwrap_spec(sizehint=int)
 def resizelist_hint(space, w_iterable, sizehint):
     if not isinstance(w_iterable, W_ListObject):
-        raise OperationError(space.w_TypeError,
-                             space.wrap("arg 1 must be a 'list'"))
+        raise oefmt(space.w_TypeError, "arg 1 must be a 'list'")
     w_iterable._resize_hint(sizehint)
 
 @unwrap_spec(sizehint=int)
@@ -181,8 +179,7 @@
     elif space.is_w(space.type(w_obj), space.w_str):
         jit.promote_string(space.str_w(w_obj))
     elif space.is_w(space.type(w_obj), space.w_unicode):
-        raise OperationError(space.w_TypeError, space.wrap(
-                             "promoting unicode unsupported"))
+        raise oefmt(space.w_TypeError, "promoting unicode unsupported")
     else:
         jit.promote(w_obj)
     return w_obj
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -88,8 +88,7 @@
         ctype = self.ctype
         if not isinstance(ctype, W_CTypeFunc):
             space = self.space
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("expected a function ctype"))
+            raise oefmt(space.w_TypeError, "expected a function ctype")
         return ctype
 
     def hide_object(self):
@@ -219,8 +218,8 @@
                                              invoke_callback,
                                              unique_id)
         if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK:
-            raise OperationError(space.w_SystemError,
-                space.wrap("libffi failed to build this callback"))
+            raise oefmt(space.w_SystemError,
+                        "libffi failed to build this callback")
 
     def py_invoke(self, ll_res, ll_args):
         jitdriver1.jit_merge_point(callback=self,
@@ -234,9 +233,9 @@
     space = fresult.space
     if isinstance(fresult, W_CTypeVoid):
         if not space.is_w(w_res, space.w_None):
-            raise OperationError(space.w_TypeError,
-                    space.wrap("callback with the return type 'void'"
-                               " must return None"))
+            raise oefmt(space.w_TypeError,
+                        "callback with the return type 'void' must return "
+                        "None")
         return
     #
     small_result = encode_result_for_libffi and fresult.size < SIZE_OF_FFI_ARG
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -113,8 +113,9 @@
                 if requires_ordering:
                     if (isinstance(self.ctype, W_CTypePrimitive) or
                         isinstance(w_other.ctype, W_CTypePrimitive)):
-                        raise OperationError(space.w_TypeError, space.wrap(
-                            "cannot do comparison on a primitive cdata"))
+                        raise oefmt(space.w_TypeError,
+                                    "cannot do comparison on a primitive "
+                                    "cdata")
                     ptr1 = rffi.cast(lltype.Unsigned, ptr1)
                     ptr2 = rffi.cast(lltype.Unsigned, ptr2)
                 result = op(ptr1, ptr2)
@@ -175,22 +176,18 @@
         space = self.space
         #
         if space.is_w(w_slice.w_start, space.w_None):
-            raise OperationError(space.w_IndexError,
-                                 space.wrap("slice start must be specified"))
+            raise oefmt(space.w_IndexError, "slice start must be specified")
         start = space.int_w(w_slice.w_start)
         #
         if space.is_w(w_slice.w_stop, space.w_None):
-            raise OperationError(space.w_IndexError,
-                                 space.wrap("slice stop must be specified"))
+            raise oefmt(space.w_IndexError, "slice stop must be specified")
         stop = space.int_w(w_slice.w_stop)
         #
         if not space.is_w(w_slice.w_step, space.w_None):
-            raise OperationError(space.w_IndexError,
-                                 space.wrap("slice with step not supported"))
+            raise oefmt(space.w_IndexError, "slice with step not supported")
         #
         if start > stop:
-            raise OperationError(space.w_IndexError,
-                                 space.wrap("slice start > stop"))
+            raise oefmt(space.w_IndexError, "slice start > stop")
         #
         ctype = self.ctype._check_slice_index(self, start, stop)
         assert isinstance(ctype, W_CTypePointer)
diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -40,8 +40,8 @@
             try:
                 datasize = ovfcheck(length * self.ctitem.size)
             except OverflowError:
-                raise OperationError(space.w_OverflowError,
-                    space.wrap("array size would overflow a ssize_t"))
+                raise oefmt(space.w_OverflowError,
+                            "array size would overflow a ssize_t")
         else:
             length = self.length
         #
@@ -55,8 +55,7 @@
     def _check_subscript_index(self, w_cdata, i):
         space = self.space
         if i < 0:
-            raise OperationError(space.w_IndexError,
-                                 space.wrap("negative index not supported"))
+            raise oefmt(space.w_IndexError, "negative index not supported")
         if i >= w_cdata.get_array_length():
             raise oefmt(space.w_IndexError,
                         "index too large for cdata '%s' (expected %d < %d)",
@@ -66,8 +65,7 @@
     def _check_slice_index(self, w_cdata, start, stop):
         space = self.space
         if start < 0:
-            raise OperationError(space.w_IndexError,
-                                 space.wrap("negative index not supported"))
+            raise oefmt(space.w_IndexError, "negative index not supported")
         if stop > w_cdata.get_array_length():
             raise oefmt(space.w_IndexError,
                         "index too large (expected %d <= %d)",
diff --git a/pypy/module/_cffi_backend/ctypefunc.py b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -471,5 +471,5 @@
         # call libffi's ffi_prep_cif() function
         res = jit_libffi.jit_ffi_prep_cif(rawmem)
         if res != clibffi.FFI_OK:
-            raise OperationError(space.w_SystemError,
-                space.wrap("libffi failed to build this function type"))
+            raise oefmt(space.w_SystemError,
+                        "libffi failed to build this function type")
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -185,26 +185,24 @@
             except OperationError, e:
                 if not e.match(space, space.w_TypeError):
                     raise
-                raise OperationError(space.w_TypeError,
-                        space.wrap("field name or array index expected"))
+                raise oefmt(space.w_TypeError,
+                            "field name or array index expected")
             return self.typeoffsetof_index(index)
         else:
             return self.typeoffsetof_field(fieldname, following)
 
     def typeoffsetof_field(self, fieldname, following):
-        space = self.space
-        msg = "with a field name argument, expected a struct or union ctype"
-        raise OperationError(space.w_TypeError, space.wrap(msg))
+        raise oefmt(self.space.w_TypeError,
+                    "with a field name argument, expected a struct or union "
+                    "ctype")
 
     def typeoffsetof_index(self, index):
-        space = self.space
-        msg = "with an integer argument, expected an array or pointer ctype"
-        raise OperationError(space.w_TypeError, space.wrap(msg))
+        raise oefmt(self.space.w_TypeError,
+                    "with an integer argument, expected an array or pointer "
+                    "ctype")
 
     def rawaddressof(self, cdata, offset):
-        space = self.space
-        raise OperationError(space.w_TypeError,
-                             space.wrap("expected a pointer ctype"))
+        raise oefmt(self.space.w_TypeError, "expected a pointer ctype")
 
     def call(self, funcaddr, args_w):
         space = self.space
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -289,8 +289,8 @@
         try:
             datasize = ovfcheck(length * itemsize)
         except OverflowError:
-            raise OperationError(space.w_OverflowError,
-                space.wrap("array size would overflow a ssize_t"))
+            raise oefmt(space.w_OverflowError,
+                        "array size would overflow a ssize_t")
         result = lltype.malloc(rffi.CCHARP.TO, datasize,
                                flavor='raw', zero=True)
         try:
@@ -322,13 +322,12 @@
         space = self.space
         ctitem = self.ctitem
         if ctitem.size < 0:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("pointer to opaque"))
+            raise oefmt(space.w_TypeError, "pointer to opaque")
         try:
             offset = ovfcheck(index * ctitem.size)
         except OverflowError:
-            raise OperationError(space.w_OverflowError,
-                    space.wrap("array offset would overflow a ssize_t"))
+            raise oefmt(space.w_OverflowError,
+                        "array offset would overflow a ssize_t")
         return ctitem, offset
 
     def rawaddressof(self, cdata, offset):
@@ -341,9 +340,8 @@
             ptr = rffi.ptradd(ptr, offset)
             return cdataobj.W_CData(space, ptr, self)
         else:
-            raise OperationError(space.w_TypeError,
-                    space.wrap("expected a cdata struct/union/array/pointer"
-                               " object"))
+            raise oefmt(space.w_TypeError,
+                        "expected a cdata struct/union/array/pointer object")
 
     def _fget(self, attrchar):
         if attrchar == 'i':     # item
@@ -377,8 +375,7 @@
     if w_fileobj.cffi_fileobj is None:
         fd = w_fileobj.direct_fileno()
         if fd < 0:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("file has no OS file descriptor"))
+            raise oefmt(space.w_ValueError, "file has no OS file descriptor")
         try:
             w_fileobj.cffi_fileobj = CffiFileObj(fd, w_fileobj.mode)
         except OSError, e:
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -94,8 +94,7 @@
         except KeyError:
             raise OperationError(space.w_KeyError, space.wrap(fieldname))
         if cfield.bitshift >= 0:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("not supported for bitfields"))
+            raise oefmt(space.w_TypeError, "not supported for bitfields")
         return (cfield.ctype, cfield.offset)
 
     def _copy_from_same(self, cdata, w_ob):
@@ -243,8 +242,8 @@
                     varsize = ovfcheck(itemsize * varsizelength)
                     size = ovfcheck(self.offset + varsize)
                 except OverflowError:
-                    raise OperationError(space.w_OverflowError,
-                        space.wrap("array size would overflow a ssize_t"))
+                    raise oefmt(space.w_OverflowError,
+                                "array size would overflow a ssize_t")
                 assert size >= 0
                 return max(size, optvarsize)
             # if 'value' was only an integer, get_new_array_length() returns
diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -44,8 +44,7 @@
             raise oefmt(space.w_ValueError,
                         "ctype '%s' is of unknown size", w_obj.name)
     else:
-        raise OperationError(space.w_TypeError,
-                            space.wrap("expected a 'cdata' or 'ctype' object"))
+        raise oefmt(space.w_TypeError, "expected a 'cdata' or 'ctype' object")
     return space.wrap(size)
 
 @unwrap_spec(w_ctype=ctypeobj.W_CType)
diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -1,6 +1,6 @@
 from __future__ import with_statement
 
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import specialize
@@ -285,8 +285,7 @@
     try:
         return _standard_object_as_bool(space, w_io)
     except _NotStandardObject:
-        raise OperationError(space.w_TypeError,
-                             space.wrap("integer/float expected"))
+        raise oefmt(space.w_TypeError, "integer/float expected")
 
 # ____________________________________________________________
 
@@ -300,8 +299,7 @@
     else:
         explicitlength = space.getindex_w(w_value, space.w_OverflowError)
         if explicitlength < 0:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("negative array length"))
+            raise oefmt(space.w_ValueError, "negative array length")
         return (space.w_None, explicitlength)
 
 # ____________________________________________________________
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -181,16 +181,14 @@
     else:
         length = space.getindex_w(w_length, space.w_OverflowError)
         if length < 0:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("negative array length"))
+            raise oefmt(space.w_ValueError, "negative array length")
     return _new_array_type(space, w_ctptr, length)
 
 @jit.elidable
 def _new_array_type(space, w_ctptr, length):
     _setup_wref(rweakref.has_weakref_support())
     if not isinstance(w_ctptr, ctypeptr.W_CTypePointer):
-        raise OperationError(space.w_TypeError,
-                             space.wrap("first arg must be a pointer ctype"))
+        raise oefmt(space.w_TypeError, "first arg must be a pointer ctype")
     arrays = w_ctptr._array_types
     if arrays is None:
         arrays = rweakref.RWeakValueDictionary(int, ctypearray.W_CTypeArray)
@@ -212,8 +210,8 @@
         try:
             arraysize = ovfcheck(length * ctitem.size)
         except OverflowError:
-            raise OperationError(space.w_OverflowError,
-                space.wrap("array size would overflow a ssize_t"))
+            raise oefmt(space.w_OverflowError,
+                        "array size would overflow a ssize_t")
         extra = '[%d]' % length
     #
     ctype = ctypearray.W_CTypeArray(space, w_ctptr, length, arraysize, extra)
@@ -290,9 +288,9 @@
     sflags = complete_sflags(sflags)
     if (not isinstance(w_ctype, ctypestruct.W_CTypeStructOrUnion)
             or w_ctype.size >= 0):
-        raise OperationError(space.w_TypeError,
-                             space.wrap("first arg must be a non-initialized"
-                                        " struct or union ctype"))
+        raise oefmt(space.w_TypeError,
+                    "first arg must be a non-initialized struct or union "
+                    "ctype")
 
     is_union = isinstance(w_ctype, ctypestruct.W_CTypeUnion)
     alignment = 1
@@ -310,8 +308,7 @@
         w_field = fields_w[i]
         field_w = space.fixedview(w_field)
         if not (2 <= len(field_w) <= 4):
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("bad field descr"))
+            raise oefmt(space.w_TypeError, "bad field descr")
         fname = space.str_w(field_w[0])
         ftype = space.interp_w(ctypeobj.W_CType, field_w[1])
         fbitsize = -1
@@ -564,14 +561,13 @@
     enumerators_w = space.fixedview(w_enumerators)
     enumvalues_w  = space.fixedview(w_enumvalues)
     if len(enumerators_w) != len(enumvalues_w):
-        raise OperationError(space.w_ValueError,
-                             space.wrap("tuple args must have the same size"))
+        raise oefmt(space.w_ValueError, "tuple args must have the same size")
     enumerators = [space.str_w(w) for w in enumerators_w]
     #
     if (not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveSigned) and
         not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveUnsigned)):
-        raise OperationError(space.w_TypeError,
-              space.wrap("expected a primitive signed or unsigned base type"))
+        raise oefmt(space.w_TypeError,
+                    "expected a primitive signed or unsigned base type")
     #
     lvalue = lltype.malloc(rffi.CCHARP.TO, w_basectype.size, flavor='raw')
     try:
@@ -601,8 +597,8 @@
     fargs = []
     for w_farg in space.fixedview(w_fargs):
         if not isinstance(w_farg, ctypeobj.W_CType):
-            raise OperationError(space.w_TypeError,
-                space.wrap("first arg must be a tuple of ctype objects"))
+            raise oefmt(space.w_TypeError,
+                        "first arg must be a tuple of ctype objects")
         if isinstance(w_farg, ctypearray.W_CTypeArray):
             w_farg = w_farg.ctptr
         fargs.append(w_farg)
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -119,9 +119,7 @@
     if space.is_true(space.callable(w_search_function)):
         state.codec_search_path.append(w_search_function)
     else:
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("argument must be callable"))
+        raise oefmt(space.w_TypeError, "argument must be callable")
 
 
 @unwrap_spec(encoding=str)
@@ -148,19 +146,17 @@
         space.call_function(w_import, space.wrap("encodings"))
         state.codec_need_encodings = False
         if len(state.codec_search_path) == 0:
-            raise OperationError(
-                space.w_LookupError,
-                space.wrap("no codec search functions registered: "
-                           "can't find encoding"))
+            raise oefmt(space.w_LookupError,
+                        "no codec search functions registered: can't find "
+                        "encoding")
     for w_search in state.codec_search_path:
         w_result = space.call_function(w_search,
                                        space.wrap(normalized_encoding))
         if not space.is_w(w_result, space.w_None):
             if not (space.isinstance_w(w_result, space.w_tuple) and
                     space.len_w(w_result) == 4):
-                raise OperationError(
-                    space.w_TypeError,
-                    space.wrap("codec search functions must return 4-tuples"))
+                raise oefmt(space.w_TypeError,
+                            "codec search functions must return 4-tuples")
             else:
                 state.codec_search_cache[normalized_encoding] = w_result
                 state.modified()
@@ -178,22 +174,19 @@
     except OperationError, e:
         if not e.match(space, space.w_AttributeError):
             raise
-        raise OperationError(space.w_TypeError, space.wrap(
-            "wrong exception"))
+        raise oefmt(space.w_TypeError, "wrong exception")
 
     delta = space.int_w(w_end) - space.int_w(w_start)
     if delta < 0 or not (space.isinstance_w(w_obj, space.w_str) or
                          space.isinstance_w(w_obj, space.w_unicode)):
-        raise OperationError(space.w_TypeError, space.wrap(
-            "wrong exception"))
+        raise oefmt(space.w_TypeError, "wrong exception")
 
 def strict_errors(space, w_exc):
     check_exception(space, w_exc)
     if space.isinstance_w(w_exc, space.w_BaseException):
         raise OperationError(space.type(w_exc), w_exc)
     else:
-        raise OperationError(space.w_TypeError, space.wrap(
-            "codec must pass exception instance"))
+        raise oefmt(space.w_TypeError, "codec must pass exception instance")
 
 def ignore_errors(space, w_exc):
     check_exception(space, w_exc)
@@ -350,9 +343,8 @@
     if space.is_true(w_decoder):
         w_res = space.call_function(w_decoder, w_obj, space.wrap(errors))
         if (not space.isinstance_w(w_res, space.w_tuple) or space.len_w(w_res) != 2):
-            raise OperationError(
-                space.w_TypeError,
-                space.wrap("encoder must return a tuple (object, integer)"))
+            raise oefmt(space.w_TypeError,
+                        "encoder must return a tuple (object, integer)")
         return space.getitem(w_res, space.wrap(0))
     else:
         assert 0, "XXX, what to do here?"
@@ -371,9 +363,7 @@
     if space.is_true(space.callable(w_handler)):
         state.codec_error_registry[errors] = w_handler
     else:
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("handler must be callable"))
+        raise oefmt(space.w_TypeError, "handler must be callable")
 
 # ____________________________________________________________
 # delegation to runicode
diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -4,7 +4,7 @@
 from pypy.interpreter.typedef import TypeDef, make_weakref_descr
 from pypy.interpreter.typedef import GetSetProperty
 from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from rpython.rlib.debug import check_nonneg
 
 
@@ -76,9 +76,8 @@
 
     def checklock(self, lock):
         if lock is not self.lock:
-            raise OperationError(
-                self.space.w_RuntimeError,
-                self.space.wrap("deque mutated during iteration"))
+            raise oefmt(self.space.w_RuntimeError,
+                        "deque mutated during iteration")
 
     def init(self, w_iterable=None, w_maxlen=None):
         space = self.space
@@ -200,8 +199,7 @@
     def pop(self):
         "Remove and return the rightmost element."
         if self.len == 0:
-            msg = "pop from an empty deque"
-            raise OperationError(self.space.w_IndexError, self.space.wrap(msg))
+            raise oefmt(self.space.w_IndexError, "pop from an empty deque")
         self.len -= 1
         ri = self.rightindex
         w_obj = self.rightblock.data[ri]
@@ -224,8 +222,7 @@
     def popleft(self):
         "Remove and return the leftmost element."
         if self.len == 0:
-            msg = "pop from an empty deque"
-            raise OperationError(self.space.w_IndexError, self.space.wrap(msg))
+            raise oefmt(self.space.w_IndexError, "pop from an empty deque")
         self.len -= 1
         li = self.leftindex
         w_obj = self.leftblock.data[li]
@@ -263,8 +260,7 @@
             if index >= BLOCKLEN:
                 block = block.rightlink
                 index = 0
-        raise OperationError(space.w_ValueError,
-                             space.wrap("deque.remove(x): x not in deque"))
+        raise oefmt(space.w_ValueError, "deque.remove(x): x not in deque")
 
     def reverse(self):
         "Reverse *IN PLACE*."
@@ -371,8 +367,7 @@
             b, i = self.locate(start)
             return b.data[i]
         else:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("deque[:] is not supported"))
+            raise oefmt(space.w_TypeError, "deque[:] is not supported")
 
     def setitem(self, w_index, w_newobj):
         space = self.space
@@ -381,8 +376,7 @@
             b, i = self.locate(start)
             b.data[i] = w_newobj
         else:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("deque[:] is not supported"))
+            raise oefmt(space.w_TypeError, "deque[:] is not supported")
 
     def delitem(self, w_index):
         space = self.space
@@ -390,8 +384,7 @@
         if step == 0:  # index only
             self.del_item(start)
         else:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("deque[:] is not supported"))
+            raise oefmt(space.w_TypeError, "deque[:] is not supported")
 
     def copy(self):
         "Return a shallow copy of a deque."
@@ -520,13 +513,12 @@
         return self.space.wrap(self.counter)
 
     def next(self):
+        space = self.space
         if self.lock is not self.deque.lock:
             self.counter = 0
-            raise OperationError(
-                self.space.w_RuntimeError,
-                self.space.wrap("deque mutated during iteration"))
+            raise oefmt(space.w_RuntimeError, "deque mutated during iteration")
         if self.counter == 0:
-            raise OperationError(self.space.w_StopIteration, self.space.w_None)
+            raise OperationError(space.w_StopIteration, space.w_None)
         self.counter -= 1
         ri = self.index
         w_x = self.block.data[ri]
@@ -563,13 +555,12 @@
         return self.space.wrap(self.counter)
 
     def next(self):
+        space = self.space
         if self.lock is not self.deque.lock:
             self.counter = 0
-            raise OperationError(
-                self.space.w_RuntimeError,
-                self.space.wrap("deque mutated during iteration"))
+            raise oefmt(space.w_RuntimeError, "deque mutated during iteration")
         if self.counter == 0:
-            raise OperationError(self.space.w_StopIteration, self.space.w_None)
+            raise OperationError(space.w_StopIteration, space.w_None)
         self.counter -= 1
         ri = self.index
         w_x = self.block.data[ri]
diff --git a/pypy/module/_csv/interp_csv.py b/pypy/module/_csv/interp_csv.py
--- a/pypy/module/_csv/interp_csv.py
+++ b/pypy/module/_csv/interp_csv.py
@@ -106,18 +106,17 @@
 
     # validate options
     if not (0 <= tmp_quoting < 4):
-        raise OperationError(space.w_TypeError,
-                             space.wrap('bad "quoting" value'))
+        raise oefmt(space.w_TypeError, 'bad "quoting" value')
 
     if dialect.delimiter == '\0':
-        raise OperationError(space.w_TypeError,
-                             space.wrap('"delimiter" must be a 1-character string'))
+        raise oefmt(space.w_TypeError,
+                    '"delimiter" must be a 1-character string')
 
     if space.is_w(w_quotechar, space.w_None) and w_quoting is None:
         tmp_quoting = QUOTE_NONE
     if tmp_quoting != QUOTE_NONE and dialect.quotechar == '\0':
-        raise OperationError(space.w_TypeError,
-                        space.wrap('quotechar must be set if quoting enabled'))
+        raise oefmt(space.w_TypeError,
+                    "quotechar must be set if quoting enabled")
     dialect.quoting = tmp_quoting
     return dialect
 
diff --git a/pypy/module/_csv/interp_reader.py b/pypy/module/_csv/interp_reader.py
--- a/pypy/module/_csv/interp_reader.py
+++ b/pypy/module/_csv/interp_reader.py
@@ -1,6 +1,6 @@
 from rpython.rlib.rstring import StringBuilder
 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 unwrap_spec
 from pypy.interpreter.typedef import TypeDef, interp2app
 from pypy.interpreter.typedef import interp_attrproperty_w, interp_attrproperty
@@ -27,10 +27,9 @@
 
     def error(self, msg):
         space = self.space
-        msg = 'line %d: %s' % (self.line_num, msg)
         w_module = space.getbuiltinmodule('_csv')
         w_error = space.getattr(w_module, space.wrap('Error'))
-        raise OperationError(w_error, space.wrap(msg))
+        raise oefmt(w_error, "line %d: %s", self.line_num, msg)
     error._dont_inline_ = True
 
     def add_char(self, field_builder, c):
diff --git a/pypy/module/_demo/demo.py b/pypy/module/_demo/demo.py
--- a/pypy/module/_demo/demo.py
+++ b/pypy/module/_demo/demo.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import oefmt
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
@@ -22,8 +22,7 @@
 def measuretime(space, repetitions, w_callable):
     if repetitions <= 0:
         w_DemoError = get(space, 'DemoError')
-        msg = "repetition count must be > 0"
-        raise OperationError(w_DemoError, space.wrap(msg))
+        raise oefmt(w_DemoError, "repetition count must be > 0")
     starttime = time(0)
     for i in range(repetitions):
         space.call_function(w_callable)
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -94,19 +94,16 @@
 
     def check_closed(self):
         if self.stream is None:
-            raise OperationError(self.space.w_ValueError,
-                self.space.wrap("I/O operation on closed file")
-            )
+            raise oefmt(self.space.w_ValueError,
+                        "I/O operation on closed file")
 
     def check_readable(self):
         if not self.readable:
-            raise OperationError(self.space.w_IOError, self.space.wrap(
-                "File not open for reading"))
+            raise oefmt(self.space.w_IOError, "File not open for reading")
 
     def check_writable(self):
         if not self.writable:
-            raise OperationError(self.space.w_IOError, self.space.wrap(
-                "File not open for writing"))
+            raise oefmt(self.space.w_IOError, "File not open for writing")
 
     def getstream(self):
         """Return self.stream or raise an app-level ValueError if missing
@@ -512,8 +509,9 @@
                     else:
                         line = w_line.charbuf_w(space)
                 except BufferInterfaceNotFound:
-                    raise OperationError(space.w_TypeError, space.wrap(
-                        "writelines() argument must be a sequence of strings"))
+                    raise oefmt(space.w_TypeError,
+                                "writelines() argument must be a sequence of "
+                                "strings")
                 else:
                     lines[i] = space.wrap(line)
         for w_line in lines:
diff --git a/pypy/module/_file/interp_stream.py b/pypy/module/_file/interp_stream.py
--- a/pypy/module/_file/interp_stream.py
+++ b/pypy/module/_file/interp_stream.py
@@ -3,7 +3,7 @@
 from rpython.rlib import streamio
 from rpython.rlib.streamio import StreamErrors
 
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root, CannotHaveLock
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.gateway import interp2app
@@ -58,14 +58,12 @@
 
     def lock(self):
         if not self._try_acquire_lock():
-            raise OperationError(self.space.w_RuntimeError,
-                                 self.space.wrap("stream lock already held"))
+            raise oefmt(self.space.w_RuntimeError, "stream lock already held")
 
     def unlock(self):
         me = self.space.getexecutioncontext()   # used as thread ident
         if self.slockowner is not me:
-            raise OperationError(self.space.w_RuntimeError,
-                                 self.space.wrap("stream lock is not held"))
+            raise oefmt(self.space.w_RuntimeError, "stream lock is not held")
         self._release_lock()
 
     def _cleanup_(self):
diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py
--- a/pypy/module/_hashlib/interp_hashlib.py
+++ b/pypy/module/_hashlib/interp_hashlib.py
@@ -7,7 +7,7 @@
 from rpython.tool.sourcetools import func_renamer
 
 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 unwrap_spec, interp2app
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.module.thread.os_lock import Lock
@@ -85,8 +85,7 @@
     def digest_type_by_name(self, space):
         digest_type = ropenssl.EVP_get_digestbyname(self.name)
         if not digest_type:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("unknown hash function"))
+            raise oefmt(space.w_ValueError, "unknown hash function")
         return digest_type
 
     def descr_repr(self, space):
diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -42,8 +42,7 @@
         ##     self.lock.free()
         self.lock = space.allocate_lock()
         self.owner = 0
-        self.operr = OperationError(space.w_RuntimeError,
-                                    space.wrap("reentrant call"))
+        self.operr = oefmt(space.w_RuntimeError, "reentrant call")
 
     def __enter__(self):
         if not self.lock.acquire(False):
@@ -91,8 +90,7 @@
         w_data = space.call_method(self, "read", space.wrap(length))
 
         if not space.isinstance_w(w_data, space.w_str):
-            raise OperationError(space.w_TypeError, space.wrap(
-                "read() should return bytes"))
+            raise oefmt(space.w_TypeError, "read() should return bytes")
         data = space.str_w(w_data)
         rwbuffer.setslice(0, data)
         return space.wrap(len(data))
@@ -157,8 +155,8 @@
 
     def _init(self, space):
         if self.buffer_size <= 0:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "buffer size must be strictly positive"))
+            raise oefmt(space.w_ValueError,
+                        "buffer size must be strictly positive")
 
         self.buffer = ['\0'] * self.buffer_size
 
@@ -171,11 +169,10 @@
 
     def _check_init(self, space):
         if self.state == STATE_ZERO:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "I/O operation on uninitialized object"))
+            raise oefmt(space.w_ValueError,
+                        "I/O operation on uninitialized object")
         elif self.state == STATE_DETACHED:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "raw stream has been detached"))
+            raise oefmt(space.w_ValueError, "raw stream has been detached")
 
     def _check_closed(self, space, message=None):
         self._check_init(space)
@@ -185,8 +182,8 @@
         w_pos = space.call_method(self.w_raw, "tell")
         pos = space.r_longlong_w(w_pos)
         if pos < 0:
-            raise OperationError(space.w_IOError, space.wrap(
-                "raw stream returned invalid position"))
+            raise oefmt(space.w_IOError,
+                        "raw stream returned invalid position")
 
         self.abs_pos = pos
         return pos
@@ -297,8 +294,8 @@
                                   space.wrap(pos), space.wrap(whence))
         pos = space.r_longlong_w(w_pos)
         if pos < 0:
-            raise OperationError(space.w_IOError, space.wrap(
-                "Raw stream returned invalid position"))
+            raise oefmt(space.w_IOError,
+                        "Raw stream returned invalid position")
         self.abs_pos = pos
         return pos
 
@@ -363,8 +360,7 @@
 
         written = space.getindex_w(w_written, space.w_IOError)
         if not 0 <= written <= len(data):
-            raise OperationError(space.w_IOError, space.wrap(
-                "raw write() returned invalid length"))
+            raise oefmt(space.w_IOError, "raw write() returned invalid length")
         if self.abs_pos != -1:
             self.abs_pos += written
         return written
@@ -417,8 +413,8 @@
                 with self.lock:
                     res = self._read_generic(space, size)
         else:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "read length must be positive or -1"))
+            raise oefmt(space.w_ValueError,
+                        "read length must be positive or -1")
         return space.wrap(res)
 
     @unwrap_spec(size=int)
@@ -454,8 +450,7 @@
         self._check_closed(space, "read of closed file")
 
         if size < 0:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "read length must be positive"))
+            raise oefmt(space.w_ValueError, "read length must be positive")
         if size == 0:
             return space.wrap("")
 
@@ -537,9 +532,9 @@
             raise BlockingIOError()
         size = space.int_w(w_size)
         if size < 0 or size > length:
-            raise OperationError(space.w_IOError, space.wrap(
-                "raw readinto() returned invalid length %d "
-                "(should have been between 0 and %d)" % (size, length)))
+            raise oefmt(space.w_IOError,
+                        "raw readinto() returned invalid length %d (should "
+                        "have been between 0 and %d)", size, length)
         if self.abs_pos != -1:
             self.abs_pos += size
         return size
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -70,8 +70,7 @@
             size = space.r_longlong_w(w_size)
 
         if size < 0:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "negative size value"))
+            raise oefmt(space.w_ValueError, "negative size value")
 
         self.truncate(size)
         if size == pos:
@@ -94,16 +93,13 @@
 
         if whence == 0:
             if pos < 0:
-                raise OperationError(space.w_ValueError, space.wrap(
-                    "negative seek value"))
+                raise oefmt(space.w_ValueError, "negative seek value")
         elif whence == 1:
             if pos > sys.maxint - self.tell():
-                raise OperationError(space.w_OverflowError, space.wrap(
-                    "new position too large"))
+                raise oefmt(space.w_OverflowError, "new position too large")
         elif whence == 2:
             if pos > sys.maxint - self.getsize():
-                raise OperationError(space.w_OverflowError, space.wrap(
-                    "new position too large"))
+                raise oefmt(space.w_OverflowError, "new position too large")
         else:
             raise oefmt(space.w_ValueError,
                         "whence must be between 0 and 2, not %d", whence)
@@ -148,8 +144,8 @@
         self.write_w(space, w_content)
         pos = space.int_w(w_pos)
         if pos < 0:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "position value cannot be negative"))
+            raise oefmt(space.w_ValueError,
+                        "position value cannot be negative")
         self.seek(pos)
         if not space.is_w(w_dict, space.w_None):
             space.call_method(self.getdict(space), "update", w_dict)
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -1,6 +1,7 @@
 from pypy.interpreter.typedef import TypeDef, interp_attrproperty, GetSetProperty
 from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.error import OperationError, wrap_oserror, wrap_oserror2
+from pypy.interpreter.error import (
+    OperationError, oefmt, wrap_oserror, wrap_oserror2)
 from rpython.rlib.rarithmetic import r_longlong
 from rpython.rlib.rstring import StringBuilder
 from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC
@@ -12,8 +13,7 @@
     def fget(space, obj):
         w_value = getattr(obj, name)
         if w_value is None:
-            raise OperationError(space.w_AttributeError,
-                                 space.wrap(name))
+            raise OperationError(space.w_AttributeError, space.wrap(name))
         else:
             return w_value
     def fset(space, obj, w_value):
@@ -21,8 +21,7 @@
     def fdel(space, obj):
         w_value = getattr(obj, name)
         if w_value is None:
-            raise OperationError(space.w_AttributeError,
-                                 space.wrap(name))
+            raise OperationError(space.w_AttributeError, space.wrap(name))
         setattr(obj, name, None)
 
     return GetSetProperty(fget, fset, fdel, cls=cls, doc=doc)
@@ -32,8 +31,8 @@
 O_APPEND = getattr(os, "O_APPEND", 0)
 
 def _bad_mode(space):
-    raise OperationError(space.w_ValueError, space.wrap(
-        "Must have exactly one of read/write/append mode"))
+    raise oefmt(space.w_ValueError,
+                "Must have exactly one of read/write/append mode")
 
 def decode_mode(space, mode):
     flags = 0
@@ -70,8 +69,7 @@
             readable = writable = True
             plus = True
         else:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "invalid mode: %s" % (mode,)))
+            raise oefmt(space.w_ValueError, "invalid mode: %s", mode)
 
     if not rwa:
         _bad_mode(space)
@@ -133,8 +131,8 @@
     @unwrap_spec(mode=str, closefd=int)
     def descr_init(self, space, w_name, mode='r', closefd=True):
         if space.isinstance_w(w_name, space.w_float):
-            raise OperationError(space.w_TypeError, space.wrap(
-                "integer argument expected, got float"))
+            raise oefmt(space.w_TypeError,
+                        "integer argument expected, got float")
 
         fd = -1
         try:
@@ -143,8 +141,7 @@
             pass
         else:
             if fd < 0:
-                raise OperationError(space.w_ValueError, space.wrap(
-                    "negative file descriptor"))
+                raise oefmt(space.w_ValueError, "negative file descriptor")
 
         self.readable, self.writable, self.appending, flags = decode_mode(space, mode)
 
@@ -162,8 +159,8 @@
             else:
                 self.closefd = True
                 if not closefd:
-                    raise OperationError(space.w_ValueError, space.wrap(
-                        "Cannot use closefd=False with file name"))
+                    raise oefmt(space.w_ValueError,
+                                "Cannot use closefd=False with file name")
 
                 from pypy.module.posix.interp_posix import (
                     dispatch_filename, rposix)
@@ -219,15 +216,11 @@
 
     def _check_readable(self, space):
         if not self.readable:
-            raise OperationError(
-                space.w_ValueError,
-                space.wrap("file not open for reading"))
+            raise oefmt(space.w_ValueError, "file not open for reading")
 
     def _check_writable(self, space):
         if not self.writable:
-            raise OperationError(
-                space.w_ValueError,
-                space.wrap("file not open for writing"))
+            raise oefmt(space.w_ValueError, "file not open for writing")
 
     def _close(self, space):
         if self.fd < 0:
diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -89,25 +89,19 @@
         rawmode += "+"
 
     if universal and (writing or appending):
-        raise OperationError(space.w_ValueError,
-            space.wrap("can't use U and writing mode at once")
-        )
+        raise oefmt(space.w_ValueError, "can't use U and writing mode at once")
     if text and binary:
-        raise OperationError(space.w_ValueError,
-            space.wrap("can't have text and binary mode at once")
-        )
+        raise oefmt(space.w_ValueError,
+                    "can't have text and binary mode at once")
     if reading + writing + appending > 1:
-        raise OperationError(space.w_ValueError,
-            space.wrap("must have exactly one of read/write/append mode")
-        )
+        raise oefmt(space.w_ValueError,
+                    "must have exactly one of read/write/append mode")
     if binary and encoding is not None:
-        raise OperationError(space.w_ValueError,
-            space.wrap("binary mode doesn't take an encoding argument")
-        )
+        raise oefmt(space.w_ValueError,
+                    "binary mode doesn't take an encoding argument")
     if binary and newline is not None:
-        raise OperationError(space.w_ValueError,
-            space.wrap("binary mode doesn't take a newline argument")
-        )
+        raise oefmt(space.w_ValueError,
+                    "binary mode doesn't take a newline argument")
     w_raw = space.call_function(
         space.gettypefor(W_FileIO), w_file, space.wrap(rawmode), space.wrap(closefd)
     )
@@ -132,15 +126,11 @@
                     buffering = st.st_blksize
 
     if buffering < 0:
-        raise OperationError(space.w_ValueError,
-            space.wrap("invalid buffering size")
-        )
+        raise oefmt(space.w_ValueError, "invalid buffering size")
 
     if buffering == 0:
         if not binary:
-            raise OperationError(space.w_ValueError,
-                space.wrap("can't have unbuffered text I/O")
-            )
+            raise oefmt(space.w_ValueError, "can't have unbuffered text I/O")
         return w_raw
 
     if updating:
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -36,23 +36,17 @@
 # May be called with any object
 def check_readable_w(space, w_obj):
     if not space.is_true(space.call_method(w_obj, 'readable')):
-        raise OperationError(
-            space.w_IOError,
-            space.wrap("file or stream is not readable"))
+        raise oefmt(space.w_IOError, "file or stream is not readable")
 
 # May be called with any object
 def check_writable_w(space, w_obj):
     if not space.is_true(space.call_method(w_obj, 'writable')):
-        raise OperationError(
-            space.w_IOError,
-            space.wrap("file or stream is not writable"))
+        raise oefmt(space.w_IOError, "file or stream is not writable")
 
 # May be called with any object
 def check_seekable_w(space, w_obj):
     if not space.is_true(space.call_method(w_obj, 'seekable')):
-        raise OperationError(
-            space.w_IOError,
-            space.wrap("file or stream is not seekable"))
+        raise oefmt(space.w_IOError, "file or stream is not seekable")
 
 
 class W_IOBase(W_Root):
@@ -129,9 +123,7 @@
 
     def flush_w(self, space):
         if self._CLOSED():
-            raise OperationError(
-                space.w_ValueError,
-                space.wrap("I/O operation on closed file"))
+            raise oefmt(space.w_ValueError, "I/O operation on closed file")
 
     def seek_w(self, space, w_offset, w_whence=None):
         self._unsupportedoperation(space, "seek")
@@ -349,8 +341,7 @@
                 break
 
             if not space.isinstance_w(w_data, space.w_str):
-                raise OperationError(space.w_TypeError, space.wrap(
-                    "read() should return bytes"))
+                raise oefmt(space.w_TypeError, "read() should return bytes")
             data = space.str_w(w_data)
             if not data:
                 break
diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -89,9 +89,8 @@
         self.buf = list(initval)
         pos = space.getindex_w(w_pos, space.w_TypeError)
         if pos < 0:
-            raise OperationError(space.w_ValueError,
-                space.wrap("position value cannot be negative")
-            )
+            raise oefmt(space.w_ValueError,
+                        "position value cannot be negative")
         self.pos = pos
         if not space.is_w(w_dict, space.w_None):
             if not space.isinstance_w(w_dict, space.w_dict):
@@ -203,9 +202,7 @@
         elif mode == 0 and pos < 0:
             raise oefmt(space.w_ValueError, "negative seek position: %d", pos)
         elif mode != 0 and pos != 0:
-            raise OperationError(space.w_IOError,
-                space.wrap("Can't do nonzero cur-relative seeks")
-            )
+            raise oefmt(space.w_IOError, "Can't do nonzero cur-relative seeks")
 
         # XXX: this makes almost no sense, but its how CPython does it.
         if mode == 1:
diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -59,8 +59,8 @@
     @unwrap_spec(final=int)
     def decode_w(self, space, w_input, final=False):
         if self.w_decoder is None:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "IncrementalNewlineDecoder.__init__ not called"))
+            raise oefmt(space.w_ValueError,
+                        "IncrementalNewlineDecoder.__init__ not called")
 
         # decode input (with the eventual \r from a previous pass)
         if not space.is_w(self.w_decoder, space.w_None):
@@ -70,8 +70,8 @@
             w_output = w_input
 
         if not space.isinstance_w(w_output, space.w_unicode):
-            raise OperationError(space.w_TypeError, space.wrap(
-                "decoder should return a string result"))
+            raise oefmt(space.w_TypeError,
+                        "decoder should return a string result")
 
         output = space.unicode_w(w_output)
         output_len = len(output)
@@ -287,8 +287,7 @@
         if space.isinstance_w(w_encoding, space.w_str):
             return w_encoding
 
-    raise OperationError(space.w_IOError, space.wrap(
-            "could not determine default encoding"))
+    raise oefmt(space.w_IOError, "could not determine default encoding")
 
 class PositionCookie(object):
     def __init__(self, bigint):
@@ -377,8 +376,8 @@
             newline = space.unicode_w(w_newline)
         if newline and newline not in (u'\n', u'\r\n', u'\r'):
             r = space.str_w(space.repr(w_newline))
-            raise OperationError(space.w_ValueError, space.wrap(
-                "illegal newline value: %s" % (r,)))
+            raise oefmt(space.w_ValueError,
+                        "illegal newline value: %s", r)
 
         self.line_buffering = line_buffering
 
@@ -429,13 +428,13 @@
 
     def _check_init(self, space):
         if self.state == STATE_ZERO:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "I/O operation on uninitialized object"))
+            raise oefmt(space.w_ValueError,
+                        "I/O operation on uninitialized object")
 
     def _check_attached(self, space):
         if self.state == STATE_DETACHED:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "underlying buffer has been detached"))
+            raise oefmt(space.w_ValueError,
+                        "underlying buffer has been detached")
         self._check_init(space)
 
     def _check_closed(self, space, message=None):
@@ -548,7 +547,7 @@
         remain buffered in the decoder, yet to be converted."""
 
         if not self.w_decoder:
-            raise OperationError(space.w_IOError, space.wrap("not readable"))
+            raise oefmt(space.w_IOError, "not readable")
 
         if self.telling:
             # To prepare for tell(), we need to snapshot a point in the file
@@ -602,7 +601,7 @@
         self._check_attached(space)
         self._check_closed(space)
         if not self.w_decoder:
-            raise OperationError(space.w_IOError, space.wrap("not readable"))
+            raise oefmt(space.w_IOError, "not readable")
 
         size = convert_size(space, w_size)
         self._writeflush(space)
@@ -741,11 +740,11 @@
         self._check_closed(space)
 
         if not self.w_encoder:
-            raise OperationError(space.w_IOError, space.wrap("not writable"))
+            raise oefmt(space.w_IOError, "not writable")
 
         if not space.isinstance_w(w_text, space.w_unicode):
-            msg = "unicode argument expected, got '%T'"
-            raise oefmt(space.w_TypeError, msg, w_text)
+            raise oefmt(space.w_TypeError,
+                        "unicode argument expected, got '%T'", w_text)
 
         text = space.unicode_w(w_text)
         textlen = len(text)
@@ -845,14 +844,13 @@
         self._check_attached(space)
 
         if not self.seekable:
-            raise OperationError(space.w_IOError, space.wrap(
-                "underlying stream is not seekable"))
+            raise oefmt(space.w_IOError, "underlying stream is not seekable")
 
         if whence == 1:
             # seek relative to current position
             if not space.is_true(space.eq(w_pos, space.wrap(0))):
-                raise OperationError(space.w_IOError, space.wrap(
-                    "can't do nonzero cur-relative seeks"))
+                raise oefmt(space.w_IOError,
+                            "can't do nonzero cur-relative seeks")
             # Seeking to the current position should attempt to sync the
             # underlying buffer with the current position.
             w_pos = space.call_method(self, "tell")
@@ -860,8 +858,8 @@
         elif whence == 2:
             # seek relative to end of file
             if not space.is_true(space.eq(w_pos, space.wrap(0))):
-                raise OperationError(space.w_IOError, space.wrap(
-                    "can't do nonzero end-relative seeks"))
+                raise oefmt(space.w_IOError,
+                            "can't do nonzero end-relative seeks")
             space.call_method(self, "flush")
             self._set_decoded_chars(None)
             self.snapshot = None
@@ -871,13 +869,14 @@
                                      w_pos, space.wrap(whence))
 
         elif whence != 0:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "invalid whence (%d, should be 0, 1 or 2)" % (whence,)))
+            raise oefmt(space.w_ValueError,
+                        "invalid whence (%d, should be 0, 1 or 2)",
+                        whence)
 
         if space.is_true(space.lt(w_pos, space.wrap(0))):
             r = space.str_w(space.repr(w_pos))
-            raise OperationError(space.w_ValueError, space.wrap(
-                "negative seek position %s" % (r,)))
+            raise oefmt(space.w_ValueError,
+                        "negative seek position %s", r)
 
         space.call_method(self, "flush")
 
@@ -914,8 +913,8 @@
 
             # Skip chars_to_skip of the decoded characters
             if len(self.decoded_chars) < cookie.chars_to_skip:
-                raise OperationError(space.w_IOError, space.wrap(
-                    "can't restore logical file position"))
+                raise oefmt(space.w_IOError,
+                            "can't restore logical file position")
             self.decoded_chars_used = cookie.chars_to_skip
         else:
             self.snapshot = PositionSnapshot(cookie.dec_flags, "")
@@ -930,12 +929,11 @@
         self._check_closed(space)
 
         if not self.seekable:
-            raise OperationError(space.w_IOError, space.wrap(
-                "underlying stream is not seekable"))
+            raise oefmt(space.w_IOError, "underlying stream is not seekable")
 
         if not self.telling:
-            raise OperationError(space.w_IOError, space.wrap(
-                "telling position disabled by next() call"))
+            raise oefmt(space.w_IOError,
+                        "telling position disabled by next() call")
 
         self._writeflush(space)
         space.call_method(self, "flush")
@@ -1008,8 +1006,8 @@
                 cookie.need_eof = 1
 
                 if chars_decoded < chars_to_skip:
-                    raise OperationError(space.w_IOError, space.wrap(
-                        "can't reconstruct logical file position"))
+                    raise oefmt(space.w_IOError,
+                                "can't reconstruct logical file position")
         finally:
             space.call_method(self.w_decoder, "setstate", w_saved_state)
 
@@ -1025,9 +1023,8 @@
         self._check_attached(space)
         size = space.int_w(w_size)
         if size <= 0:
-            raise OperationError(space.w_ValueError,
-                space.wrap("a strictly positive integer is required")
-            )
+            raise oefmt(space.w_ValueError,
+                        "a strictly positive integer is required")
         self.chunk_size = size
 
 W_TextIOWrapper.typedef = TypeDef(
diff --git a/pypy/module/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py
--- a/pypy/module/_locale/interp_locale.py
+++ b/pypy/module/_locale/interp_locale.py
@@ -1,7 +1,7 @@
 from rpython.rlib import rposix
 from rpython.rlib.rarithmetic import intmask
 
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import unwrap_spec
 
 from rpython.rlib import rlocale
@@ -186,8 +186,7 @@
         try:
             return space.wrap(rlocale.nl_langinfo(key))
         except ValueError:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("unsupported langinfo constant"))
+            raise oefmt(space.w_ValueError, "unsupported langinfo constant")
 
 #___________________________________________________________________
 # HAVE_LIBINTL dependence
diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py
--- a/pypy/module/_lsprof/interp_lsprof.py
+++ b/pypy/module/_lsprof/interp_lsprof.py
@@ -1,7 +1,7 @@
 import py
 
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.function import Method, Function
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import (TypeDef, GetSetProperty,
@@ -418,9 +418,9 @@
     def getstats(self, space):
         if self.w_callable is None:
             if self.is_enabled:
-                raise OperationError(space.w_RuntimeError,
-                    space.wrap("Profiler instance must be disabled "
-                               "before getting the stats"))
+                raise oefmt(space.w_RuntimeError,
+                            "Profiler instance must be disabled before "
+                            "getting the stats")
             if self.total_timestamp:
                 factor = self.total_real_time / float(self.total_timestamp)
             else:
diff --git a/pypy/module/_multibytecodec/interp_multibytecodec.py b/pypy/module/_multibytecodec/interp_multibytecodec.py
--- a/pypy/module/_multibytecodec/interp_multibytecodec.py
+++ b/pypy/module/_multibytecodec/interp_multibytecodec.py
@@ -1,7 +1,7 @@
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.module._multibytecodec import c_codecs
 from pypy.module._codecs.interp_codecs import CodecState
 
@@ -57,8 +57,7 @@
     try:
         codec = c_codecs.getcodec(name)
     except KeyError:
-        raise OperationError(space.w_LookupError,
-                             space.wrap("no such codec is supported."))


More information about the pypy-commit mailing list