diff options
author | Carey Metcalfe <carey@cmetcalfe.ca> | 2023-05-01 07:32:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 07:32:04 (GMT) |
commit | 487f55d5801a9ae7d79d37e259e8c377c9acd39b (patch) | |
tree | 75fec7a70ef0819fca6769c0c20aa1b552eea70f /Python | |
parent | 93107aa2a49a9354ffb10b3cd263dc3e99ebdeff (diff) | |
download | cpython-487f55d5801a9ae7d79d37e259e8c377c9acd39b.zip cpython-487f55d5801a9ae7d79d37e259e8c377c9acd39b.tar.gz cpython-487f55d5801a9ae7d79d37e259e8c377c9acd39b.tar.bz2 |
gh-103895: Improve how invalid `Exception.__notes__` are displayed (#103897)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index b16d3f5..05e7b43 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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); |