3

I have the most simplest class derived from Exception, looks something like this:

class Test(Exception):
    '''
    My Test class 
    '''
    def __init__(self, param=None):
        self.param = param

    def __str__(self):
        return 'Test representation'

    def foo(self):
        '''Perform a foo'''
        print 'Fubar'

When I run help() on this module, I get :

class Test(exceptions.Exception)
 |  My Test class
 |
 |  Method resolution order:
 |      Test
 |      exceptions.Exception
 |      exceptions.BaseException
 |      __builtin__.object
 |
 |  Methods defined here:
 |
 |  __init__(self, param=None)
 |
 |  __str__(self)
 |
 |  foo(self)
 |      Perform a foo
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __weakref__
 |      list of weak references to the object (if defined)
 |
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from exceptions.Exception:
 |
 |  __new__ = <built-in method __new__ of type object>
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from exceptions.BaseException:
 |
 |  __delattr__(...)
 |      x.__delattr__('name') <==> del x.name
 |
 |  __getattribute__(...)
 |      x.__getattribute__('name') <==> x.name
 |
 |  __getitem__(...)
 |      x.__getitem__(y) <==> x[y]
 |
 |  __getslice__(...)
 |      x.__getslice__(i, j) <==> x[i:j]
 |
 |      Use of negative indices is not supported.
 |
 |  __reduce__(...)
 |
 |  __repr__(...)
 |      x.__repr__() <==> repr(x)
 |
 |  __setattr__(...)
 |      x.__setattr__('name', value) <==> x.name = value
 |
 |  __setstate__(...)
 |
 |  __unicode__(...)
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from exceptions.BaseException:
 |
 |  __dict__
 |
 |  args
 |
 |  message

That's a terrible amount of noise which is irrelevant to the documentation of the class. How do I suppress all that?

[Edit] I'd like it to be more like what I'd get if the class wasn't inherited from Exception

Like this :

class Test
 |  My Test class
 |
 |  Methods defined here:
 |
 |  __init__(self, param=None)
 |
 |  __str__(self)
 |
 |  foo(self)
 |      Perform a foo
rep_movsd
  • 6,675
  • 4
  • 30
  • 34
  • That's doing exactly what it's supposed to. What do you want instead? – jonrsharpe Dec 01 '14 at 21:01
  • If you want just the class' docstring, you could do `print Test.__doc__` or `print inspect.getdoc(Test)`. –  Dec 01 '14 at 21:04
  • I want it not to show the stuff related to the base classes – rep_movsd Dec 01 '14 at 21:26
  • 1
    This amount of clutter is normal for the `help()` function (e.g. try `help(dict)` or similar at the REPL). If you build documentation with something like [Sphinx](http://sphinx-doc.org/), you can get more readable output, and it'll also be available as nicely formatted HTML in addition to plain text. – Kevin Dec 01 '14 at 21:47

1 Answers1

1

if you type:

help(help) 

You should read:

Help on _Helper in module site object:

class _Helper(__builtin__.object)
 |  Define the builtin 'help'.
 |  This is a wrapper around pydoc.help (with a twist).
 ...

Which means you should be able to write your "own" helper function. It seems you should take a look at pydocs implementation of help().

Don Question
  • 11,227
  • 5
  • 36
  • 54