Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 45818:ff0ab7b28f49 legacy-trunk
- Issue #2371: Add a Py3k warning when catching an exception that
doesn't derive from BaseException.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 18 Mar 2008 02:49:46 +0000 |
| parents | 343597c7d682 |
| children | 79fdc88ff9ec |
line wrap: on
line diff
--- a/Python/ceval.c Tue Mar 18 01:58:56 2008 +0000 +++ b/Python/ceval.c Tue Mar 18 02:49:46 2008 +0000 @@ -4042,6 +4042,13 @@ } } +#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 @@ 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 @@ 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;
