[issue45635] Tidy up error handling in traceback.c / python run.c

Irit Katriel report at bugs.python.org
Mon Nov 1 07:23:33 EDT 2021


Irit Katriel <iritkatriel at gmail.com> added the comment:

It's more intricate than I initially thought - the assertion that no exception is set is in PyObject_Str rather than PyFile_WriteObject, and it should remain there because it ensures that exceptions are not accidentally cleared by an str() call.

In the traceback display code, there are places where the exception is cleared because it's being overridden (like when modulename is not found and is replace by "<unknown>") or places where the code makes a best-effort attempt to print something anyway. In these situations the error is cleared before calling PyFile_WriteObject. It is probably correct, but it's hard to follow the logic when making changes to the code, so it should be made more explicit.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45635>
_______________________________________


More information about the Python-bugs-list mailing list