all Python 3inspectfunction
inspect.istraceback()
stack and frames
Checks that an object is a traceback (types.TracebackType), such as e.__traceback__ or sys.exc_info()[2].
Syntax
inspect.istraceback(object) -> bool
An exception is not a traceback: istraceback(e) is False, you need e.__traceback__. A traceback is a linked list: tb.tb_next leads to the next frame closer to the error, tb.tb_frame to the frame itself. An exception that was created but never raised has __traceback__ set to None, and the check filters that case out too.
Examples
import inspect
try:
1 / 0
except ZeroDivisionError as e:
err = e
print(inspect.istraceback(err), inspect.istraceback(err.__traceback__)) # → False True
print(inspect.istraceback(ValueError('x').__traceback__)) # → False — не возбуждалось
See also
Open in the full glossarydocs.python.orgReport an inaccuracy