You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
which means that PyFile_XXX functions are called after error. They should return (abort printing the exception) instead.
It gets even more interesting with PyFile_WriteObject calls - this function asserts that the exception is not set, so the code calls PyErr_Clear() before calling PyFile_WriteObject(). It should avoid making the call altogether.
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.