Author: Ronan Lamy <[email protected]>
Branch: 
Changeset: r84139:d1f09c46b8e7
Date: 2016-05-02 19:19 +0100
http://bitbucket.org/pypy/pypy/changeset/d1f09c46b8e7/

Log:    Don't use deprecated raise statement syntax

diff --git a/pypy/doc/tool/mydot.py b/pypy/doc/tool/mydot.py
--- a/pypy/doc/tool/mydot.py
+++ b/pypy/doc/tool/mydot.py
@@ -68,7 +68,7 @@
                       help="output format")
     options, args = parser.parse_args()
     if len(args) != 1:
-        raise ValueError, "need exactly one argument"
+        raise ValueError("need exactly one argument")
     epsfile = process_dot(py.path.local(args[0]))
     if options.format == "ps" or options.format == "eps":
         print epsfile.read()
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -134,11 +134,11 @@
         """The simplest argument parsing: get the 'argcount' arguments,
         or raise a real ValueError if the length is wrong."""
         if self.keywords:
-            raise ValueError, "no keyword arguments expected"
+            raise ValueError("no keyword arguments expected")
         if len(self.arguments_w) > argcount:
-            raise ValueError, "too many arguments (%d expected)" % argcount
+            raise ValueError("too many arguments (%d expected)" % argcount)
         elif len(self.arguments_w) < argcount:
-            raise ValueError, "not enough arguments (%d expected)" % argcount
+            raise ValueError("not enough arguments (%d expected)" % argcount)
         return self.arguments_w
 
     def firstarg(self):
diff --git a/pypy/interpreter/astcompiler/tools/asdl.py 
b/pypy/interpreter/astcompiler/tools/asdl.py
--- a/pypy/interpreter/astcompiler/tools/asdl.py
+++ b/pypy/interpreter/astcompiler/tools/asdl.py
@@ -96,7 +96,7 @@
 
     def t_default(self, s):
         r" . +"
-        raise ValueError, "unmatched input: %s" % `s`
+        raise ValueError("unmatched input: %s" % `s`)
 
 class ASDLParser(spark.GenericParser, object):
     def __init__(self):
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -550,7 +550,7 @@
         where the order is according to self.pycode.signature()."""
         scope_len = len(scope_w)
         if scope_len > self.pycode.co_nlocals:
-            raise ValueError, "new fastscope is longer than the allocated area"
+            raise ValueError("new fastscope is longer than the allocated area")
         # don't assign directly to 'locals_cells_stack_w[:scope_len]' to be
         # virtualizable-friendly
         for i in range(scope_len):
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1110,7 +1110,7 @@
         return next_instr
 
     def FOR_LOOP(self, oparg, next_instr):
-        raise BytecodeCorruption, "old opcode, no longer in use"
+        raise BytecodeCorruption("old opcode, no longer in use")
 
     def SETUP_LOOP(self, offsettoend, next_instr):
         block = LoopBlock(self, next_instr + offsettoend, self.lastblock)
diff --git a/pypy/interpreter/test/test_exceptcomp.py 
b/pypy/interpreter/test/test_exceptcomp.py
--- a/pypy/interpreter/test/test_exceptcomp.py
+++ b/pypy/interpreter/test/test_exceptcomp.py
@@ -7,7 +7,7 @@
 
     def test_exception(self):
         try:
-            raise TypeError, "nothing"
+            raise TypeError("nothing")
         except TypeError:
             pass
         except:
@@ -15,7 +15,7 @@
 
     def test_exceptionfail(self):
         try:
-            raise TypeError, "nothing"
+            raise TypeError("nothing")
         except KeyError:
             self.fail("Different exceptions match.")
         except TypeError:
@@ -47,7 +47,7 @@
         class UserExcept(Exception):
             pass
         try:
-            raise UserExcept, "nothing"
+            raise UserExcept("nothing")
         except UserExcept:
             pass
         except:
diff --git a/pypy/interpreter/test/test_typedef.py 
b/pypy/interpreter/test/test_typedef.py
--- a/pypy/interpreter/test/test_typedef.py
+++ b/pypy/interpreter/test/test_typedef.py
@@ -13,7 +13,7 @@
         # XXX why is this called newstring?
         import sys
         def f():
-            raise TypeError, "hello"
+            raise TypeError("hello")
 
         def g():
             f()
@@ -23,7 +23,7 @@
         except:
             typ,val,tb = sys.exc_info()
         else:
-            raise AssertionError, "should have raised"
+            raise AssertionError("should have raised")
         assert hasattr(tb, 'tb_frame')
         assert hasattr(tb, 'tb_lasti')
         assert hasattr(tb, 'tb_lineno')
diff --git a/pypy/module/__builtin__/test/test_classobj.py 
b/pypy/module/__builtin__/test/test_classobj.py
--- a/pypy/module/__builtin__/test/test_classobj.py
+++ b/pypy/module/__builtin__/test/test_classobj.py
@@ -688,7 +688,7 @@
 
     def test_catch_attributeerror_of_descriptor(self):
         def booh(self):
-            raise this_exception, "booh"
+            raise this_exception("booh")
 
         class E:
             __eq__ = property(booh)
diff --git a/pypy/module/__builtin__/test/test_descriptor.py 
b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -322,7 +322,7 @@
         except ZeroDivisionError:
             pass
         else:
-            raise Exception, "expected ZeroDivisionError from bad property"
+            raise Exception("expected ZeroDivisionError from bad property")
 
     def test_property_subclass(self):
         class P(property):
diff --git a/pypy/module/imp/test/test_import.py 
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -1135,7 +1135,7 @@
                 if fullname in self.namestoblock:
                     return self
             def load_module(self, fullname):
-                raise ImportError, "blocked"
+                raise ImportError("blocked")
 
         import sys, imp
         modname = "errno" # an arbitrary harmless builtin module
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -199,10 +199,10 @@
             g._childpid = childpid
             return g
 
-        except Exception, e:
+        except Exception as e:
             try_close(write_end)
             try_close(read_end)
-            raise Exception, e     # bare 'raise' does not work here :-(
+            raise e     # bare 'raise' does not work here :-(
 
     def wait():
         """ wait() -> (pid, status)
diff --git a/pypy/module/signal/test/test_signal.py 
b/pypy/module/signal/test/test_signal.py
--- a/pypy/module/signal/test/test_signal.py
+++ b/pypy/module/signal/test/test_signal.py
@@ -197,7 +197,7 @@
             except OSError:
                 pass
             else:
-                raise AssertionError, "os.read(fd_read, 1) succeeded?"
+                raise AssertionError("os.read(fd_read, 1) succeeded?")
         #
         fd_read, fd_write = posix.pipe()
         flags = fcntl.fcntl(fd_write, fcntl.F_GETFL, 0)
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -58,7 +58,7 @@
     # note that we cannot use SystemExit(exitcode) here.
     # The comma version leads to an extra de-tupelizing
     # in normalize_exception, which is exactly like CPython's.
-    raise SystemExit, exitcode
+    raise SystemExit(exitcode)
 
 def exitfunc():
     """Placeholder for sys.exitfunc(), which is called when PyPy exits."""
diff --git a/pypy/module/sys/test/test_sysmodule.py 
b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -83,7 +83,7 @@
             etype, val, tb = sys.exc_info()
             assert isinstance(val, etype)
         else:
-            raise AssertionError, "ZeroDivisionError not caught"
+            raise AssertionError("ZeroDivisionError not caught")
 
     def test_io(self):
         import sys
@@ -280,7 +280,7 @@
 
         def clear():
             try:
-                raise ValueError, 42
+                raise ValueError(42)
             except ValueError, exc:
                 clear_check(exc)
 
@@ -290,7 +290,7 @@
         # Verify that a frame currently handling an exception is
         # unaffected by calling exc_clear in a nested frame.
         try:
-            raise ValueError, 13
+            raise ValueError(13)
         except ValueError, exc:
             typ1, value1, traceback1 = sys.exc_info()
             clear()
@@ -314,9 +314,9 @@
         except SystemExit, exc:
             assert exc.code == 0
         except:
-            raise AssertionError, "wrong exception"
+            raise AssertionError("wrong exception")
         else:
-            raise AssertionError, "no exception"
+            raise AssertionError("no exception")
 
         # call with tuple argument with one entry
         # entry will be unpacked
@@ -325,9 +325,9 @@
         except SystemExit, exc:
             assert exc.code == 42
         except:
-            raise AssertionError, "wrong exception"
+            raise AssertionError("wrong exception")
         else:
-            raise AssertionError, "no exception"
+            raise AssertionError("no exception")
 
         # call with integer argument
         try:
@@ -335,9 +335,9 @@
         except SystemExit, exc:
             assert exc.code == 42
         except:
-            raise AssertionError, "wrong exception"
+            raise AssertionError("wrong exception")
         else:
-            raise AssertionError, "no exception"
+            raise AssertionError("no exception")
 
         # call with string argument
         try:
@@ -345,9 +345,9 @@
         except SystemExit, exc:
             assert exc.code == "exit"
         except:
-            raise AssertionError, "wrong exception"
+            raise AssertionError("wrong exception")
         else:
-            raise AssertionError, "no exception"
+            raise AssertionError("no exception")
 
         # call with tuple argument with two entries
         try:
@@ -355,9 +355,9 @@
         except SystemExit, exc:
             assert exc.code == (17, 23)
         except:
-            raise AssertionError, "wrong exception"
+            raise AssertionError("wrong exception")
         else:
-            raise AssertionError, "no exception"
+            raise AssertionError("no exception")
 
     def test_getdefaultencoding(self):
         import sys
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py
@@ -5,7 +5,7 @@
 
 def callback_func(arg):
     42 / arg
-    raise ValueError, arg
+    raise ValueError(arg)
 
 class TestCallbackTraceback:
     # When an exception is raised in a ctypes callback function, the C
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py
@@ -190,7 +190,7 @@
     class stdcall_dll(WinDLL):
         def __getattr__(self, name):
             if name[:2] == '__' and name[-2:] == '__':
-                raise AttributeError, name
+                raise AttributeError(name)
             func = self._FuncPtr(("s_" + name, self))
             setattr(self, name, func)
             return func
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
@@ -513,7 +513,7 @@
             assert ("Structure or union cannot contain itself" in
                             str(details))
         else:
-            raise AssertionError, "Structure or union cannot contain itself"
+            raise AssertionError("Structure or union cannot contain itself")
 
     def test_vice_versa(self):
         py.test.skip("mutually dependent lazily defined structures error 
semantics")
@@ -530,7 +530,7 @@
             assert ("_fields_ is final" in
                             str(details))
         else:
-            raise AssertionError, "AttributeError not raised"
+            raise AssertionError("AttributeError not raised")
 
     def test_nonfinal_struct(self):
         class X(Structure):
@@ -558,7 +558,7 @@
             _fields_ = [('x', c_int)]
 
             def __getattr__(self, name):
-                raise AttributeError, name
+                raise AttributeError(name)
 
         x = X()
         assert x.x == 0
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -893,4 +893,4 @@
         elif _name not in ['is_', 'id','type','issubtype', 'int',
                            # not really to be defined in DescrOperation
                            'ord', 'unichr', 'unicode']:
-            raise Exception, "missing def for operation %s" % _name
+            raise Exception("missing def for operation %s" % _name)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -143,7 +143,7 @@
         if x is None:
             return self.w_None
         if isinstance(x, OperationError):
-            raise TypeError, ("attempt to wrap already wrapped exception: %s"%
+            raise TypeError("attempt to wrap already wrapped exception: %s"%
                               (x,))
         if isinstance(x, int):
             if isinstance(x, bool):
diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -241,7 +241,7 @@
                 return super(WorkOnce, self).__new__(WorkOnce, name, bases, ns)
             def mro(instance):
                 if instance.flag > 0:
-                    raise RuntimeError, "bozo"
+                    raise RuntimeError("bozo")
                 else:
                     instance.flag += 1
                     return type.mro(instance)
diff --git a/pypy/objspace/test/test_descroperation.py 
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -149,7 +149,7 @@
             def __setslice__(self, start, stop, sequence):
                 ops.append((start, stop, sequence))
             def __setitem__(self, key, value):
-                raise AssertionError, key
+                raise AssertionError(key)
             def __len__(self):
                 return 100
 
@@ -174,7 +174,7 @@
             def __delslice__(self, start, stop):
                 ops.append((start, stop))
             def __delitem__(self, key):
-                raise AssertionError, key
+                raise AssertionError(key)
             def __len__(self):
                 return 100
 
diff --git a/pypy/tool/importfun.py b/pypy/tool/importfun.py
--- a/pypy/tool/importfun.py
+++ b/pypy/tool/importfun.py
@@ -163,7 +163,7 @@
         if name in opcode.opmap:
             return opcode.opmap[name]
         else:
-            raise AttributeError, name
+            raise AttributeError(name)
 
 _op_ = _Op()
 
diff --git a/pypy/tool/isolate.py b/pypy/tool/isolate.py
--- a/pypy/tool/isolate.py
+++ b/pypy/tool/isolate.py
@@ -50,7 +50,7 @@
             if exc_type_module == 'exceptions':
                 raise getattr(exceptions, exc_type_name)
             else:
-                raise IsolateException, "%s.%s" % value 
+                raise IsolateException("%s.%s" % value) 
 
     def _close(self):
         if not self._closed:
diff --git a/pypy/tool/pydis.py b/pypy/tool/pydis.py
--- a/pypy/tool/pydis.py
+++ b/pypy/tool/pydis.py
@@ -96,8 +96,8 @@
         for bytecode in self.bytecodes:
             if bytecode.index == index:
                 return bytecode
-        raise ValueError, "no bytecode found on index %s in code \n%s" % (
-                index, pydis(self.code))
+        raise ValueError("no bytecode found on index %s in code \n%s" % (
+                index, pydis(self.code)))
 
     def format(self):
         lastlineno = -1
diff --git a/pypy/tool/pytest/test/test_pytestsupport.py 
b/pypy/tool/pytest/test/test_pytestsupport.py
--- a/pypy/tool/pytest/test/test_pytestsupport.py
+++ b/pypy/tool/pytest/test/test_pytestsupport.py
@@ -49,7 +49,7 @@
     except AssertionError:
         pass
     else:
-        raise AssertionError, "app level AssertionError mixup!"
+        raise AssertionError("app level AssertionError mixup!")
 
 def app_test_exception_with_message():
     try:
diff --git a/pypy/tool/rest/rst.py b/pypy/tool/rest/rst.py
--- a/pypy/tool/rest/rst.py
+++ b/pypy/tool/rest/rst.py
@@ -128,7 +128,7 @@
         outcome = []
         if (isinstance(self.children[0], Transition) or
                 isinstance(self.children[-1], Transition)):
-            raise ValueError, ('document must not begin or end with a '
+            raise ValueError('document must not begin or end with a '
                                'transition')
         for child in self.children:
             outcome.append(child.text())
diff --git a/pypy/tool/test/isolate_simple.py b/pypy/tool/test/isolate_simple.py
--- a/pypy/tool/test/isolate_simple.py
+++ b/pypy/tool/test/isolate_simple.py
@@ -3,13 +3,13 @@
     return a+b
 
 def g():
-    raise ValueError, "booh"
+    raise ValueError("booh")
 
 class FancyException(Exception):
     pass
 
 def h():
-    raise FancyException, "booh"
+    raise FancyException("booh")
 
 def bomb():
     raise KeyboardInterrupt
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to