[issue39725] unrelated `from None` exceptions lose prior exception information
Serhiy Storchaka
report at bugs.python.org
Sat Feb 22 17:00:45 EST 2020
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
Interesting problem.
Example which does not depend on os.environ:
import traceback
try:
try:
raise TypeError
except:
try:
raise ValueError
except:
raise KeyError from None
except BaseException as exc:
e = exc
print([e, e.__cause__, e.__context__, e.__suppress_context__])
traceback.print_exception(type(e), e, e.__traceback__)
"from None" sets __suppress_context__ to True. Currently, if __suppress_context__ is true, the output of __context__ will be suppressed in the traceback. But what if we suppress only a part __context__ and output the "original" exception. The problem is what is the "original" exception. Is it __context__.__context__? Or __context__.__cause__ if it is not None? Should we take __context__.__suppress_context__ into account? Maybe go down recursively?
----------
nosy: +benjamin.peterson
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39725>
_______________________________________
More information about the Python-bugs-list
mailing list