summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2008-03-18 02:49:46 (GMT)
committerGuido van Rossum <guido@python.org>2008-03-18 02:49:46 (GMT)
commit04edb528ca39d25a019e7b391a3b5a69156848fe (patch)
tree115e9a3fb067da94b2249b39c29bd6ce38197047 /Python/ceval.c
parent0bb7950829839cf321c15638851550f0d79a6df7 (diff)
downloadcpython-04edb528ca39d25a019e7b391a3b5a69156848fe.zip
cpython-04edb528ca39d25a019e7b391a3b5a69156848fe.tar.gz
cpython-04edb528ca39d25a019e7b391a3b5a69156848fe.tar.bz2
- Issue #2371: Add a Py3k warning when catching an exception that
doesn't derive from BaseException.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 4fc1709..72da263 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4042,6 +4042,13 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
}
}
+#define Py3kExceptionClass_Check(x) \
+ (PyType_Check((x)) && \
+ PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
+
+#define CANNOT_CATCH_MSG "catching classes that don't inherit from " \
+ "BaseException is not allowed in 3.x."
+
static PyObject *
cmp_outcome(int op, register PyObject *v, register PyObject *w)
{
@@ -4079,6 +4086,16 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
if (ret_val == -1)
return NULL;
}
+ if (Py_Py3kWarningFlag &&
+ !Py3kExceptionClass_Check(exc))
+ {
+ int ret_val;
+ ret_val = PyErr_WarnEx(
+ PyExc_DeprecationWarning,
+ CANNOT_CATCH_MSG, 1);
+ if (ret_val == -1)
+ return NULL;
+ }
}
}
else {
@@ -4091,6 +4108,16 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
if (ret_val == -1)
return NULL;
}
+ if (Py_Py3kWarningFlag &&
+ !Py3kExceptionClass_Check(w))
+ {
+ int ret_val;
+ ret_val = PyErr_WarnEx(
+ PyExc_DeprecationWarning,
+ CANNOT_CATCH_MSG, 1);
+ if (ret_val == -1)
+ return NULL;
+ }
}
res = PyErr_GivenExceptionMatches(v, w);
break;