diff options
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index e9522e8..bc43799 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -266,28 +266,35 @@ BaseException_get_cause(PyObject *self) { PyObject *res = PyException_GetCause(self); if (res) return res; /* new reference already returned above */ - Py_RETURN_NONE; + Py_INCREF(Py_Ellipsis); + return Py_Ellipsis; } -static int -BaseException_set_cause(PyObject *self, PyObject *arg) { - if (arg == NULL) { - PyErr_SetString(PyExc_TypeError, "__cause__ may not be deleted"); - return -1; - } else if (arg == Py_None) { +int +_PyException_SetCauseChecked(PyObject *self, PyObject *arg) { + if (arg == Py_Ellipsis) { arg = NULL; - } else if (!PyExceptionInstance_Check(arg)) { - PyErr_SetString(PyExc_TypeError, "exception cause must be None " - "or derive from BaseException"); + } else if (arg != Py_None && !PyExceptionInstance_Check(arg)) { + PyErr_SetString(PyExc_TypeError, "exception cause must be None, " + "Ellipsis or derive from BaseException"); return -1; } else { - /* PyException_SetCause steals this reference */ + /* PyException_SetCause steals a reference */ Py_INCREF(arg); } PyException_SetCause(self, arg); return 0; } +static int +BaseException_set_cause(PyObject *self, PyObject *arg) { + if (arg == NULL) { + PyErr_SetString(PyExc_TypeError, "__cause__ may not be deleted"); + return -1; + } + return _PyException_SetCauseChecked(self, arg); +} + static PyGetSetDef BaseException_getset[] = { {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |