]> granicus.if.org Git - python/commitdiff
Issue #2341: Add a Py3k warning when raising an exception that doesn't
authorGuido van Rossum <guido@python.org>
Tue, 18 Mar 2008 04:26:48 +0000 (04:26 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 18 Mar 2008 04:26:48 +0000 (04:26 +0000)
derive from BaseException.

Misc/NEWS
Python/ceval.c

index f1746b2b0998d6bbefb6f9b317f1f1c2278d5e9e..5436c252130d8684e14a473bb18c5e1657675ab2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,7 +13,8 @@ Core and builtins
 -----------------
 
 - Issue #2371: Add a Py3k warning when catching an exception that
-  doesn't derive from BaseException.
+  doesn't derive from BaseException.  Issue #2341: Add a Py3k warning
+  when raising an exception that doesn't derive from BaseException.
 
 - Issue #2321: use pymalloc for unicode object string data to reduce
   memory usage in some circumstances.
index d66d97e56bca1414a6fce49852c45131baa47e16..dc1aa52eec6ea94299a853d2f35c1b2b155aa5b5 100644 (file)
@@ -3161,6 +3161,15 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
                             type->ob_type->tp_name);
                goto raise_error;
        }
+
+       assert(PyExceptionClass_Check(type));
+       if (Py_Py3kWarningFlag && PyClass_Check(type)) {
+               if (PyErr_Warn(PyExc_DeprecationWarning,
+                              "exceptions must derive from BaseException "
+                              "in 3.x") == -1)
+                       goto raise_error;
+       }
+
        PyErr_Restore(type, value, tb);
        if (tb == NULL)
                return WHY_EXCEPTION;