Capture Additional Exception Attributes in traceback.TracebackException #111927
Labels
3.13
bugs and security fixes
stdlib
Python modules in the Lib dir
type-feature
A feature request or enhancement
Feature or enhancement
traceback.TracebackException
currently captures all the information common to all exceptions. It also captures some of the information that is specific to certain builtin exceptions, enough to print all exceptions.I don't have a motivating use case. My interest here is mostly conceptual. I think of
TracebackException
as a summary or representative proxy of an exception and currently there are gaps in that representation. IfTracebackException
is really only intended for printing exceptions/tracebacks then there probably isn't much to do here (and I'm okay with that). That said, I'll proceed here with my thoughts.There are two categories of gap-in-representation that I see:
ImportError
)Ultimately, it should probably be each exception type that determines what information should be preserved in a snapshot like
TracebackException
. That suggests room for a new protocol (i.e. "dunder" method). At the very least it would be nice to rely onexc.args
, which all exceptions have, and map that to names. For non-builtin exceptions I don't see a real alternative to a general protocol.For builtin exceptions, however, we can fill in the gaps in
TracebackException
manually, following the pattern of what we've done forSyntaxError
andExceptionGroup
.ImportError
msg
name
path
name_from
OSError
errno
winerror
strerror
filename
filename2
SystemExit
code
UnicodeError
encoding
reason
object
start
end
BlockingIOError
characters_written
BaseExceptionGroup
message
StopIteration
value
NameError
name
AttributeError
name
obj
SyntaxError
print_file_and_line
Related:
The text was updated successfully, but these errors were encountered: