Feature or enhancement
Currently traceback.TracebackException appears to expect the "exc_type" argument to be None or an exception type object. 12
In addition to exception types, I'd like to be able to pass in either a str (the type's __qualname__) or an object that has the attributes that TracebackException need in order to do its job.
For exception types the following attributes are especially important for _PyErr_Display():
__name__
__qualname__
__module__
So we would need those. If non-str were passed in then it would need to have those attrs set properly. If a str were passed in then we'd parse out the info and create a types.SimpleNamespace with that info to use instead.
My motivation is propagating exceptions between interpreters. I want to use TracebackException but have it be strictly a snapshot of an exception, whereas right now it actually still holds a reference to exc_type. It also matters when pickling, where you may not want to pickle a user-defined exception type.
Linked PRs
Feature or enhancement
Currently
traceback.TracebackExceptionappears to expect the "exc_type" argument to beNoneor an exception type object. 12In addition to exception types, I'd like to be able to pass in either a
str(the type's__qualname__) or an object that has the attributes thatTracebackExceptionneed in order to do its job.For exception types the following attributes are especially important for
_PyErr_Display():__name____qualname____module__So we would need those. If non-
strwere passed in then it would need to have those attrs set properly. If astrwere passed in then we'd parse out the info and create atypes.SimpleNamespacewith that info to use instead.My motivation is propagating exceptions between interpreters. I want to use
TracebackExceptionbut have it be strictly a snapshot of an exception, whereas right now it actually still holds a reference toexc_type. It also matters when pickling, where you may not want to pickle a user-defined exception type.Linked PRs
Footnotes
https://github.com/python/cpython/blob/6f09f69b7f85962f66d10637c3325bbb2b2d9853/Lib/traceback.py#L722 ↩
https://github.com/python/cpython/blob/6f09f69b7f85962f66d10637c3325bbb2b2d9853/Lib/traceback.py#L763 ↩