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 /Lib/traceback.py | |
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 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index 9e720ac..ba4a9ff 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -852,12 +852,16 @@ class TracebackException: yield _format_final_exc_line(stype, self._str) else: yield from self._format_syntax_error(stype) - if isinstance(self.__notes__, collections.abc.Sequence): + + if ( + isinstance(self.__notes__, collections.abc.Sequence) + and not isinstance(self.__notes__, (str, bytes)) + ): for note in self.__notes__: note = _safe_string(note, 'note') yield from [l + '\n' for l in note.split('\n')] elif self.__notes__ is not None: - yield _safe_string(self.__notes__, '__notes__', func=repr) + yield "{}\n".format(_safe_string(self.__notes__, '__notes__', func=repr)) def _format_syntax_error(self, stype): """Format SyntaxError exceptions (internal helper).""" |