summaryrefslogtreecommitdiffstats
path: root/Python
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 /Python
parentcda6b6d60d96e6f755da92deb5e4066839095791 (diff)
downloadcpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.zip
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.gz
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.bz2
Close issue #6210: Implement PEP 409
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c17
-rw-r--r--Python/pythonrun.c6
2 files changed, 14 insertions, 9 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 06bff4c..017dc4a 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3567,22 +3567,23 @@ 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_DECREF(cause);
- }
- else if (PyExceptionInstance_Check(cause)) {
+ Py_CLEAR(cause);
+ } else {
+ /* Let "exc.__cause__ = cause" handle all further checks */
fixed_cause = cause;
+ cause = NULL; /* Steal the reference */
}
- else {
- PyErr_SetString(PyExc_TypeError,
- "exception causes must derive from "
- "BaseException");
+ /* We retain ownership of the reference to fixed_cause */
+ result = _PyException_SetCauseChecked(value, fixed_cause);
+ Py_DECREF(fixed_cause);
+ if (result < 0) {
goto raise_error;
}
- PyException_SetCause(value, fixed_cause);
}
PyErr_SetObject(type, value);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index a642c0b..f4e7e7b 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1698,7 +1698,11 @@ print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen)
else if (PyExceptionInstance_Check(value)) {
cause = PyException_GetCause(value);
context = PyException_GetContext(value);
- if (cause) {
+ if (cause && cause == Py_None) {
+ /* print neither cause nor context */
+ ;
+ }
+ else if (cause) {
res = PySet_Contains(seen, cause);
if (res == -1)
PyErr_Clear();