summaryrefslogtreecommitdiff
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-05-14 22:09:31 -0700
committerBenjamin Peterson <benjamin@python.org>2012-05-14 22:09:31 -0700
commit9031c8f35aa4af460cb1507b2fc1ec8f78601327 (patch)
treec53500e8e81db30516cb33256826a8123b7dd0b1 /Python/ceval.c
parentf3ad80b549fdea8ed1977bc0b7711b50ee87ecb2 (diff)
downloadcpython-9031c8f35aa4af460cb1507b2fc1ec8f78601327.tar.gz
PEP 415: Implement suppression of __context__ display with an exception attribute
This replaces the original PEP 409 implementation. See #14133.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index b9a006b675..718bb32b56 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3572,23 +3572,26 @@ do_raise(PyObject *exc, PyObject *cause)
if (cause) {
PyObject *fixed_cause;
- int result;
if (PyExceptionClass_Check(cause)) {
fixed_cause = PyObject_CallObject(cause, NULL);
if (fixed_cause == NULL)
goto raise_error;
- Py_CLEAR(cause);
- } else {
- /* Let "exc.__cause__ = cause" handle all further checks */
+ Py_DECREF(cause);
+ }
+ else if (PyExceptionInstance_Check(cause)) {
fixed_cause = cause;
- cause = NULL; /* Steal the reference */
}
- /* We retain ownership of the reference to fixed_cause */
- result = _PyException_SetCauseChecked(value, fixed_cause);
- Py_DECREF(fixed_cause);
- if (result < 0) {
+ else if (cause == Py_None) {
+ Py_DECREF(cause);
+ fixed_cause = NULL;
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "exception causes must derive from "
+ "BaseException");
goto raise_error;
}
+ PyException_SetCause(value, fixed_cause);
}
PyErr_SetObject(type, value);