summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-02-26 07:49:52 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-02-26 07:49:52 (GMT)
commitab7bf2143e67ddc1510413fa0d7f9c621adf22fa (patch)
tree62a24ed4f57e4db638ebde745bb83e2e09fc86e3 /Objects
parentcda6b6d60d96e6f755da92deb5e4066839095791 (diff)
downloadcpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.zip
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.gz
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.bz2
Close issue #6210: Implement PEP 409
Diffstat (limited to 'Objects')
-rw-r--r--Objects/exceptions.c29
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},