mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-103895: Improve how invalid Exception.__notes__
are displayed (#103897)
This commit is contained in:
parent
93107aa2a4
commit
487f55d580
4 changed files with 23 additions and 5 deletions
|
@ -1107,7 +1107,7 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
|
|||
if (notes == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (!PySequence_Check(notes)) {
|
||||
if (!PySequence_Check(notes) || PyUnicode_Check(notes) || PyBytes_Check(notes)) {
|
||||
int res = 0;
|
||||
if (write_indented_margin(ctx, f) < 0) {
|
||||
res = -1;
|
||||
|
@ -1122,6 +1122,9 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
|
|||
Py_DECREF(s);
|
||||
}
|
||||
Py_DECREF(notes);
|
||||
if (PyFile_WriteString("\n", f) < 0) {
|
||||
res = -1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
Py_ssize_t num_notes = PySequence_Length(notes);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue