mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
(cherry picked from commit ecd21a629a
)
This commit is contained in:
parent
1d8c18c39d
commit
a8431123c2
3 changed files with 30 additions and 30 deletions
|
@ -1092,21 +1092,16 @@ error:
|
|||
}
|
||||
|
||||
static int
|
||||
print_exception_notes(struct exception_print_context *ctx, PyObject *value)
|
||||
print_exception_notes(struct exception_print_context *ctx, PyObject *notes)
|
||||
{
|
||||
PyObject *f = ctx->file;
|
||||
|
||||
if (!PyExceptionInstance_Check(value)) {
|
||||
if (notes == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *notes;
|
||||
int res = _PyObject_LookupAttr(value, &_Py_ID(__notes__), ¬es);
|
||||
if (res <= 0) {
|
||||
return res;
|
||||
}
|
||||
if (!PySequence_Check(notes) || PyUnicode_Check(notes) || PyBytes_Check(notes)) {
|
||||
res = 0;
|
||||
int res = 0;
|
||||
if (write_indented_margin(ctx, f) < 0) {
|
||||
res = -1;
|
||||
}
|
||||
|
@ -1119,7 +1114,6 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
|
|||
res = PyFile_WriteObject(s, f, Py_PRINT_RAW);
|
||||
Py_DECREF(s);
|
||||
}
|
||||
Py_DECREF(notes);
|
||||
if (PyFile_WriteString("\n", f) < 0) {
|
||||
res = -1;
|
||||
}
|
||||
|
@ -1164,17 +1158,16 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
|
|||
}
|
||||
}
|
||||
|
||||
Py_DECREF(notes);
|
||||
return 0;
|
||||
error:
|
||||
Py_XDECREF(lines);
|
||||
Py_DECREF(notes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
print_exception(struct exception_print_context *ctx, PyObject *value)
|
||||
{
|
||||
PyObject *notes = NULL;
|
||||
PyObject *f = ctx->file;
|
||||
|
||||
if (!PyExceptionInstance_Check(value)) {
|
||||
|
@ -1188,8 +1181,11 @@ print_exception(struct exception_print_context *ctx, PyObject *value)
|
|||
goto error;
|
||||
}
|
||||
|
||||
/* grab the type now because value can change below */
|
||||
/* grab the type and notes now because value can change below */
|
||||
PyObject *type = (PyObject *) Py_TYPE(value);
|
||||
if (_PyObject_LookupAttr(value, &_Py_ID(__notes__), ¬es) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (print_exception_file_and_line(ctx, &value) < 0) {
|
||||
goto error;
|
||||
|
@ -1203,14 +1199,16 @@ print_exception(struct exception_print_context *ctx, PyObject *value)
|
|||
if (PyFile_WriteString("\n", f) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (print_exception_notes(ctx, value) < 0) {
|
||||
if (print_exception_notes(ctx, notes) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
Py_XDECREF(notes);
|
||||
Py_DECREF(value);
|
||||
assert(!PyErr_Occurred());
|
||||
return 0;
|
||||
error:
|
||||
Py_XDECREF(notes);
|
||||
Py_DECREF(value);
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue