1

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?

AlexLordThorsen
  • 8,057
  • 5
  • 48
  • 103

1 Answers1

1

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.

Community
  • 1
  • 1
Brian
  • 7,394
  • 3
  • 25
  • 46