Python 中的回溯对象类型是什么?

What is the type of traceback objects in Python?

import sys

try:
    raise Exception('foobar')
except:
    info = sys.exc_info()

print(type(e[2])) # <class 'traceback'>
help(traceback) # NameError: name 'traceback' is not defined

Python 用于异常报告的回溯对象的类型究竟是什么?

sys.exc_info 上的文档提到了参考手册,但是虽然我找到了大量关于如何操作回溯实例的信息,但我希望能够访问该类型 (class)本身。

traceback 对象是类型模块下 TracebackType 的一个实例。

types.TracebackType

The type of traceback objects such as found in sys.exc_info()[2].

>>> from types import TracebackType    
>>> isinstance(info[2], TracebackType)
True    
>>> TracebackType
<class 'traceback'>

因为 the name TracebackType is basically an alias to the internal traceback type and is set by raising an exception in types module. The actual traceback type 可以在 CPython 代码中找到。