[pypy-commit] pypy py3k: merge default (oefmt pypy/module/!(_*))
Author: Philip JenveyBranch: py3k Changeset: r84161:5067460e27d9 Date: 2016-05-02 18:12 -0700 http://bitbucket.org/pypy/pypy/changeset/5067460e27d9/ Log:merge default (oefmt pypy/module/!(_*)) diff too long, truncating to 2000 out of 3288 lines diff --git a/pypy/doc/coding-guide.rst b/pypy/doc/coding-guide.rst --- a/pypy/doc/coding-guide.rst +++ b/pypy/doc/coding-guide.rst @@ -266,7 +266,13 @@ To raise an application-level exception:: -raise OperationError(space.w_XxxError, space.wrap("message")) +from pypy.interpreter.error import oefmt + +raise oefmt(space.w_XxxError, "message") + +raise oefmt(space.w_XxxError, "file '%s' not found in '%s'", filename, dir) + +raise oefmt(space.w_XxxError, "file descriptor '%d' not open", fd) To catch a specific application-level exception:: diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py --- a/pypy/module/array/interp_array.py +++ b/pypy/module/array/interp_array.py @@ -18,17 +18,16 @@ @unwrap_spec(typecode=str) def w_array(space, w_cls, typecode, __args__): if len(__args__.arguments_w) > 1: -msg = 'array() takes at most 2 arguments' -raise OperationError(space.w_TypeError, space.wrap(msg)) +raise oefmt(space.w_TypeError, "array() takes at most 2 arguments") if len(typecode) != 1: -msg = 'array() argument 1 must be char, not str' -raise OperationError(space.w_TypeError, space.wrap(msg)) +raise oefmt(space.w_TypeError, +"array() argument 1 must be char, not str") typecode = typecode[0] if space.is_w(w_cls, space.gettypeobject(W_ArrayBase.typedef)): if __args__.keywords: -msg = 'array.array() does not take keyword arguments' -raise OperationError(space.w_TypeError, space.wrap(msg)) +raise oefmt(space.w_TypeError, +"array.array() does not take keyword arguments") for tc in unroll_typecodes: if typecode == tc: @@ -52,8 +51,9 @@ a.descr_frombytes(space, buf) break else: -msg = 'bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)' -raise OperationError(space.w_ValueError, space.wrap(msg)) +raise oefmt(space.w_ValueError, +"bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f " +"or d)") return a @@ -214,8 +214,7 @@ Append items to array from list. """ if not space.isinstance_w(w_lst, space.w_list): -raise OperationError(space.w_TypeError, - space.wrap("arg must be list")) +raise oefmt(space.w_TypeError, "arg must be list") s = self.len try: self.fromsequence(w_lst) @@ -272,8 +271,8 @@ fromfile() method). """ if len(s) % self.itemsize != 0: -msg = 'string length not a multiple of item size' -raise OperationError(self.space.w_ValueError, self.space.wrap(msg)) +raise oefmt(self.space.w_ValueError, +"string length not a multiple of item size") oldlen = self.len new = len(s) / self.itemsize if not new: @@ -303,8 +302,7 @@ if n != 0: item = item[0:elems] self.descr_frombytes(space, item) -msg = "not enough items in file" -raise OperationError(space.w_EOFError, space.wrap(msg)) +raise oefmt(space.w_EOFError, "not enough items in file") self.descr_fromstring(space, w_item) def descr_tofile(self, space, w_f): @@ -332,8 +330,8 @@ if self.typecode == 'u': self.fromsequence(w_ustr) else: -msg = "fromunicode() may only be called on type 'u' arrays" -raise OperationError(space.w_ValueError, space.wrap(msg)) +raise oefmt(space.w_ValueError, +"fromunicode() may only be called on type 'u' arrays") def descr_tounicode(self, space): """ tounicode() -> unicode @@ -347,8 +345,8 @@ buf = rffi.cast(UNICODE_ARRAY, self._buffer_as_unsigned()) return space.wrap(rffi.wcharpsize2unicode(buf, self.len)) else: -msg = "tounicode() may only be called on type 'u' arrays" -raise OperationError(space.w_ValueError, space.wrap(msg)) +raise oefmt(space.w_ValueError, +"tounicode() may only be called on type 'u' arrays") def descr_buffer_info(self, space): """ buffer_info() -> (address, length) @@ -420,8 +418,8 @@ not 1, 2, 4, or 8 bytes in size, RuntimeError is raised. """ if self.itemsize not in [1, 2, 4, 8]: -msg = "byteswap not supported for this array" -raise OperationError(space.w_RuntimeError, space.wrap(msg)) +raise
[pypy-commit] pypy py3k: merge default (oefmt pypy/module/_*)
Author: Philip JenveyBranch: py3k Changeset: r84158:72ab4cdc6bd2 Date: 2016-05-02 17:47 -0700 http://bitbucket.org/pypy/pypy/changeset/72ab4cdc6bd2/ Log:merge default (oefmt pypy/module/_*) diff too long, truncating to 2000 out of 2441 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 from pypy.interpreter.argument import Arguments @@ -30,8 +30,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() @@ -39,9 +38,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', 'eval' or 'single'")) +raise oefmt(space.w_ValueError, +"compile() arg 3 must be 'exec', 'eval' or 'single'") if space.isinstance_w(w_source, space.gettypeobject(ast.W_AST.typedef)): ast_node = ast.mod.from_object(space, w_source) 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 ( @@ -100,9 +100,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) @@ -159,21 +159,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 @@ -61,8 +61,7 @@ else: w_step = space.index(w_slice.w_step) if space.is_true(space.eq(w_step, w_0)): -raise OperationError(space.w_ValueError, - space.wrap("slice step cannot be zero")) +raise oefmt(space.w_ValueError, "slice step cannot be zero") negative_step = space.is_true(space.lt(w_step, w_0)) if space.is_w(w_slice.w_start, space.w_None): if negative_step: @@ -124,16 +123,18 @@ elif len(args_w): w_sequence = args_w[0] else: -msg = "%s() expects at least one argument" % (implementation_of,) -raise