mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Close issue #6210: Implement PEP 409
This commit is contained in:
parent
cda6b6d60d
commit
ab7bf2143e
15 changed files with 263 additions and 42 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue