[Python-Dev] docstrings, help(), and __name__

David Abrahams dave@boost-consulting.com
Wed, 7 Aug 2002 18:00:50 -0400

From: "Guido van Rossum" <guido@python.org>

> > It seems I'm breaking some protocol. It's easy enough to add a
> > attribute to my function objects, but I'd like to be sure that I'm
> > everything I really /should/ add. Just how much like a regular Python
> > function does my function have to be in order to make the help system
> > other standard systems with such expectations) happy?
> It's hard to say.  The pydoc code makes up protocols as it goes.  I
> think __name__ is probably the only one you're missing in practice.

That appears to be correct. Interestingly, these methods seem to be treated
differently from ordinary ones. My methods get shown like this:

   |  __init__ = __init__(...)
   |      this is the __init__ function
   |      its documentation has two lines.

Where the 2nd instance of __init__ is given by the value of the __name__
attribute, while built-in methods get shown as follows:

  >>> class X(object):
  ...     def __init__(self): pass
  >>> help(X)
  Help on class X in module __main__:

  class X(__builtin__.object)
   |  Methods defined here:
   |  __init__(self)

Does anyone know why the difference? Is it perhaps the missing 'im_class'
attribute in my case? These are the sorts of things I want to know about...


           David Abrahams * Boost Consulting
dave@boost-consulting.com * http://www.boost-consulting.com