Python Inspect.getsourcelines(无._;str__;)抛出令人困惑的类型错误

Python Inspect.getsourcelines(无._;str__;)抛出令人困惑的类型错误,python,Python,今天,我的一个同事发现了一个有趣的案例 str(None) 'None' 所以很自然地我想看看“无”是如何定义的 inspect.getsourcelines(None.__str__) TypeError: <method-wrapper '__str__' of NoneType object at 0x91a870> is not a module, class, method, function, traceback, frame, or code object insp

今天,我的一个同事发现了一个有趣的案例

str(None)
'None'
所以很自然地我想看看“无”是如何定义的

inspect.getsourcelines(None.__str__)
TypeError: <method-wrapper '__str__' of NoneType object at 0x91a870> is not a module, class, method, function, traceback, frame, or code object
inspect.getsourcelines(无)
TypeError:不是模块、类、方法、函数、回溯、帧或代码对象
这可能并不奇怪,因为在
C
中很可能没有定义。但是这带来了一个有趣的问题,如果
None.\uuu str\uuu
不是一个模块、类、方法等等,那么它是什么

这是什么

这是一个很好的问题

>>> type(None.__str__)
<type 'method-wrapper'>
>>> None.__str__.__class__
<type 'method-wrapper'>
>>> type(None.__str__.__call__)
<type 'method-wrapper'>
>>>类型(无)
>>>无.\uuuuuuuuuuuuuuuuuuuuuuuu类__
>>>类型(无.\uuuuuu str.\uuuuuuuuu.\uuuuuuuuu调用)

现在,它取决于什么,但它肯定是一个方法包装器。

Python 2.7在2.7和3.5上都测试过吗