[pypy-commit] pypy default: modernise raise syntax

rlamy noreply at buildbot.pypy.org
Sun May 4 03:33:00 CEST 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r71252:5385c2f50d5c
Date: 2014-05-04 02:32 +0100
http://bitbucket.org/pypy/pypy/changeset/5385c2f50d5c/

Log:	modernise raise syntax

diff --git a/rpython/rtyper/callparse.py b/rpython/rtyper/callparse.py
--- a/rpython/rtyper/callparse.py
+++ b/rpython/rtyper/callparse.py
@@ -58,7 +58,7 @@
     try:
         holders = arguments.match_signature(signature, defs_h)
     except ArgErr, e:
-        raise TyperError, "signature mismatch: %s" % e.getmsg(graph.name)
+        raise TyperError("signature mismatch: %s" % e.getmsg(graph.name))
 
     assert len(holders) == len(rinputs), "argument parsing mismatch"
     vlist = []
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -257,7 +257,7 @@
         @classmethod
         def _malloc(cls, n=None):
             if not isinstance(n, int):
-                raise TypeError, "array length must be an int"
+                raise TypeError("array length must be an int")
             biggercls = get_ctypes_array_of_size(A, n)
             bigarray = allocate_ctypes(biggercls)
             if hasattr(bigarray, 'length'):
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -191,7 +191,7 @@
     _adtmeths = {}
 
     def _inline_is_varsize(self, last):
-        raise TypeError, "%r cannot be inlined in structure" % self
+        raise TypeError("%r cannot be inlined in structure" % self)
 
     def _install_extras(self, adtmeths={}, hints={}):
         self._adtmeths = frozendict(adtmeths)
@@ -253,7 +253,7 @@
         self._arrayfld = None
         for name, typ in fields:
             if name.startswith('_'):
-                raise NameError, ("%s: field name %r should not start with "
+                raise NameError("%s: field name %r should not start with "
                                   "an underscore" % (self._name, name,))
             names.append(name)
             if name in flds:
@@ -311,8 +311,8 @@
 
 
     def _nofield(self, name):
-        raise AttributeError, 'struct %s has no field %r' % (self._name,
-                                                             name)
+        raise AttributeError('struct %s has no field %r' % (self._name,
+                                                             name))
 
     def _names_without_voids(self):
         names_without_voids = [name for name in self._names if self._flds[name] is not Void]
@@ -545,7 +545,7 @@
         self.ARGS = tuple(args)
         assert isinstance(result, LowLevelType)
         if isinstance(result, ContainerType):
-            raise TypeError, "function result can only be primitive or pointer"
+            raise TypeError("function result can only be primitive or pointer")
         self.RESULT = result
         self.ABI = abi
 
@@ -602,7 +602,7 @@
         return "%s (gcopaque)" % self.tag
 
     def _inline_is_varsize(self, last):
-        raise TypeError, "%r cannot be inlined in structure" % self
+        raise TypeError("%r cannot be inlined in structure" % self)
 
 
 class ForwardReference(ContainerType):
@@ -714,7 +714,7 @@
     _cache = WeakValueDictionary()  # cache the Ptrs
     def __new__(cls, TO, use_cache=True):
         if not isinstance(TO, ContainerType):
-            raise TypeError, ("can only point to a Container type, "
+            raise TypeError("can only point to a Container type, "
                               "not to %s" % (TO,))
         if not use_cache:
             obj = LowLevelType.__new__(cls)
@@ -835,7 +835,7 @@
 def cast_primitive(TGT, value):
     ORIG = typeOf(value)
     if not isinstance(TGT, Primitive) or not isinstance(ORIG, Primitive):
-        raise TypeError, "can only primitive to primitive"
+        raise TypeError("can only primitive to primitive")
     if ORIG == TGT:
         return value
     if ORIG == Char or ORIG == UniChar:
@@ -855,7 +855,7 @@
         return float(value)
     if ORIG == LongFloat and TGT == Float:
         return float(value)
-    raise TypeError, "unsupported cast"
+    raise TypeError("unsupported cast")
 
 def _cast_whatever(TGT, value):
     from rpython.rtyper.lltypesystem import llmemory, rffi
@@ -932,13 +932,13 @@
 def cast_pointer(PTRTYPE, ptr):
     CURTYPE = typeOf(ptr)
     if not isinstance(CURTYPE, Ptr) or not isinstance(PTRTYPE, Ptr):
-        raise TypeError, "can only cast pointers to other pointers"
+        raise TypeError("can only cast pointers to other pointers")
     return ptr._cast_to(PTRTYPE)
 
 def cast_opaque_ptr(PTRTYPE, ptr):
     CURTYPE = typeOf(ptr)
     if not isinstance(CURTYPE, Ptr) or not isinstance(PTRTYPE, Ptr):
-        raise TypeError, "can only cast pointers to other pointers"
+        raise TypeError("can only cast pointers to other pointers")
     if CURTYPE == PTRTYPE:
         return ptr
     if CURTYPE.TO._gckind != PTRTYPE.TO._gckind:
@@ -989,9 +989,9 @@
     """
     CURTYPE = typeOf(structptr).TO
     if not isinstance(CURTYPE, Struct):
-        raise TypeError, "direct_fieldptr: not a struct"
+        raise TypeError("direct_fieldptr: not a struct")
     if fieldname not in CURTYPE._flds:
-        raise TypeError, "%s has no field %r" % (CURTYPE, fieldname)
+        raise TypeError("%s has no field %r" % (CURTYPE, fieldname))
     if not structptr:
         raise RuntimeError("direct_fieldptr: NULL argument")
     return _subarray._makeptr(structptr._obj, fieldname, structptr._solid)
@@ -1004,7 +1004,7 @@
     """
     CURTYPE = typeOf(arrayptr).TO
     if not isinstance(CURTYPE, (Array, FixedSizeArray)):
-        raise TypeError, "direct_arrayitems: not an array"
+        raise TypeError("direct_arrayitems: not an array")
     if not arrayptr:
         raise RuntimeError("direct_arrayitems: NULL argument")
     return _subarray._makeptr(arrayptr._obj, 0, arrayptr._solid)
@@ -1247,7 +1247,7 @@
         from rpython.rtyper.lltypesystem import rffi
         if isinstance(self._T, FuncType):
             if len(args) != len(self._T.ARGS):
-                raise TypeError,"calling %r with wrong argument number: %r" % (self._T, args)
+                raise TypeError("calling %r with wrong argument number: %r" % (self._T, args))
             for i, a, ARG in zip(range(len(self._T.ARGS)), args, self._T.ARGS):
                 if typeOf(a) != ARG:
                     # ARG could be Void
@@ -1272,11 +1272,11 @@
                         pass
                     else:
                         args_repr = [typeOf(arg) for arg in args]
-                        raise TypeError, ("calling %r with wrong argument "
+                        raise TypeError("calling %r with wrong argument "
                                           "types: %r" % (self._T, args_repr))
             callb = self._obj._callable
             if callb is None:
-                raise RuntimeError,"calling undefined function"
+                raise RuntimeError("calling undefined function")
             return callb(*args)
         raise TypeError("%r instance is not a function" % (self._T,))
 
@@ -1421,7 +1421,7 @@
         self._set_offsets(_offsets)
 
     def __nonzero__(self):
-        raise RuntimeError, "do not test an interior pointer for nullity"
+        raise RuntimeError("do not test an interior pointer for nullity")
 
     def _get_obj(self):
         ob = self._parent
@@ -1657,9 +1657,9 @@
 
     def __init__(self, TYPE, n, initialization=None, parent=None, parentindex=None):
         if not is_valid_int(n):
-            raise TypeError, "array length must be an int"
+            raise TypeError("array length must be an int")
         if n < 0:
-            raise ValueError, "negative array length"
+            raise ValueError("negative array length")
         _parentable.__init__(self, TYPE)
         myrange = self._check_range(n)
         self.items = [TYPE.OF._allocate(initialization=initialization,
@@ -1977,9 +1977,9 @@
         assert n is None
         o = _opaque(T, initialization=initialization)
     else:
-        raise TypeError, "malloc: unmallocable type"
+        raise TypeError("malloc: unmallocable type")
     if flavor == 'gc' and T._gckind != 'gc' and not immortal:
-        raise TypeError, "gc flavor malloc of a non-GC non-immortal structure"
+        raise TypeError("gc flavor malloc of a non-GC non-immortal structure")
     if flavor == "raw" and not immortal and track_allocation:
         leakfinder.remember_malloc(o, framedepth=2)
     solid = immortal or flavor == 'raw'
@@ -1987,10 +1987,10 @@
 
 def free(p, flavor, track_allocation=True):
     if flavor.startswith('gc'):
-        raise TypeError, "gc flavor free"
+        raise TypeError("gc flavor free")
     T = typeOf(p)
     if not isinstance(T, Ptr) or p._togckind() != 'raw':
-        raise TypeError, "free(): only for pointers to non-gc containers"
+        raise TypeError("free(): only for pointers to non-gc containers")
     if track_allocation:
         leakfinder.remember_free(p._obj0)
     p._obj0._free()
@@ -1998,7 +1998,7 @@
 def render_immortal(p, track_allocation=True):
     T = typeOf(p)
     if not isinstance(T, Ptr) or p._togckind() != 'raw':
-        raise TypeError, "free(): only for pointers to non-gc containers"
+        raise TypeError("free(): only for pointers to non-gc containers")
     if track_allocation:
         leakfinder.remember_free(p._obj0)
 
@@ -2033,7 +2033,7 @@
 
 def functionptr(TYPE, name, **attrs):
     if not isinstance(TYPE, FuncType):
-        raise TypeError, "functionptr() for FuncTypes only"
+        raise TypeError("functionptr() for FuncTypes only")
     try:
         hash(tuple(attrs.items()))
     except TypeError:
@@ -2046,7 +2046,7 @@
 
 def opaqueptr(TYPE, name, **attrs):
     if not isinstance(TYPE, OpaqueType):
-        raise TypeError, "opaqueptr() for OpaqueTypes only"
+        raise TypeError("opaqueptr() for OpaqueTypes only")
     o = _opaque(TYPE, _name=name, **attrs)
     return _ptr(Ptr(TYPE), o, solid=True)
 
@@ -2064,23 +2064,23 @@
 def attachRuntimeTypeInfo(GCSTRUCT, funcptr=None, destrptr=None,
                           customtraceptr=None):
     if not isinstance(GCSTRUCT, RttiStruct):
-        raise TypeError, "expected a RttiStruct: %s" % GCSTRUCT
+        raise TypeError("expected a RttiStruct: %s" % GCSTRUCT)
     GCSTRUCT._attach_runtime_type_info_funcptr(funcptr, destrptr,
                                                customtraceptr)
     return _ptr(Ptr(RuntimeTypeInfo), GCSTRUCT._runtime_type_info)
 
 def getRuntimeTypeInfo(GCSTRUCT):
     if not isinstance(GCSTRUCT, RttiStruct):
-        raise TypeError, "expected a RttiStruct: %s" % GCSTRUCT
+        raise TypeError("expected a RttiStruct: %s" % GCSTRUCT)
     if GCSTRUCT._runtime_type_info is None:
-        raise ValueError, ("no attached runtime type info for GcStruct %s" %
+        raise ValueError("no attached runtime type info for GcStruct %s" %
                            GCSTRUCT._name)
     return _ptr(Ptr(RuntimeTypeInfo), GCSTRUCT._runtime_type_info)
 
 def runtime_type_info(p):
     T = typeOf(p)
     if not isinstance(T, Ptr) or not isinstance(T.TO, RttiStruct):
-        raise TypeError, "runtime_type_info on non-RttiStruct pointer: %s" % p
+        raise TypeError("runtime_type_info on non-RttiStruct pointer: %s" % p)
     struct = p._obj
     top_parent = top_container(struct)
     result = getRuntimeTypeInfo(top_parent._TYPE)
@@ -2090,7 +2090,7 @@
         T = typeOf(query_funcptr).TO.ARGS[0]
         result2 = query_funcptr(cast_pointer(T, p))
         if result != result2:
-            raise RuntimeError, ("runtime type-info function for %s:\n"
+            raise RuntimeError("runtime type-info function for %s:\n"
                                  "        returned: %s,\n"
                                  "should have been: %s" % (p, result2, result))
     return result
diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -379,7 +379,7 @@
     def rtype_method_replace(self, hop):
         rstr = hop.args_r[0].repr
         if not (hop.args_r[1] == rstr.char_repr and hop.args_r[2] == rstr.char_repr):
-            raise TyperError, 'replace only works for char args'
+            raise TyperError('replace only works for char args')
         v_str, v_c1, v_c2 = hop.inputargs(rstr.repr, rstr.char_repr, rstr.char_repr)
         hop.exception_cannot_occur()
         return hop.gendirectcall(self.ll.ll_replace_chr_chr, v_str, v_c1, v_c2)


More information about the pypy-commit mailing list