I have a lot of callable objects and they all have the __doc__ string correctly filled out, but running help on them produces the help for their class instead of help based on __doc__.
I want to change it so that running help on them produces customized help that looks essentially like what I would get if they were actual functions instead of instances of a class that implements __call__.
In code, I'd like to make the output of this:
class myCallable:
def __init__(self, doc):
self.__doc__ = doc
def __call__(self):
# do some stuff
pass
myFunc = myCallable("some doco text")
help(myFunc)
Look more like the output of this:
def myFunc():
"some doco text"
# do some stuff
pass
help(myFunc)
The
helpfunction (implemented in thepydocmodule) isn't prepared to find per-instance docstrings. I took a quick look through the module to see if there was a way to provide explicit help, but there doesn't seem to be. It uses theinspectmodule to determine what kind of thing it is, and your myFunc doesn't look like a function, it looks like an instance. So pydoc prints help about the instance's class instead.It'd be nice if similar to
__doc__you could add a__help__attribute, but there's no support for that.I hesitate to suggest it, but your best bet might be to define a new
helpfunction:and then put a
__help__attribute on your instances: