AlexLordThorsen
AlexLordThorsen

Reputation: 8488

Inspect.getsourcelines(None.__str__) throws confusing TypeError

Today one of my co-workers found the interesting case of

str(None)
'None'

So Naturally I wanted to see how None is defined

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

Which probably isn't surprising since None's most likely defined in C. But that brings up the interesting question, if None.__str__ isn't a module, class, method, etc what is it?

Upvotes: 2

Views: 75

Answers (1)

Brian
Brian

Reputation: 7654

what is it?

It is a very good question.

>>> type(None.__str__)
<type 'method-wrapper'>
>>> None.__str__.__class__
<type 'method-wrapper'>
>>> type(None.__str__.__call__)
<type 'method-wrapper'>

Now, what it is depends on which version of python you use, but it is definitely a method-wrapper.

Upvotes: 2

Related Questions