[Numpy-discussion] How to get docs for functions processed by numpy.vectorize?

Pierre Haesssig pierre.haessig at crans.org
Fri Sep 12 08:56:58 EDT 2014


Hi,

I tried to following the calling logic behind the help function and I've 
arrived at the 3-4th level underground with the pydoc.render_doc 
function. Here some logic is inspecting the `thing` that getting 
documented. The fact that the docstring of the vectorize function is not 
read may relate to the fact that the type of a vectorized function is 
not `function` but `numpy.lib.function_base.vectorize` instead.

Here is the code that does the magic, for futher inspection :

pydoc.render_doc??

def render_doc(thing, title='Python Library Documentation: %s', 
forceload=0):
     """Render text documentation, given an object or a path to an 
object."""
     object, name = resolve(thing, forceload)
     desc = describe(object)
     module = inspect.getmodule(object)
     if name and '.' in name:
         desc += ' in ' + name[:name.rfind('.')]
     elif module and module is not object:
         desc += ' in module ' + module.__name__
     if type(object) is _OLD_INSTANCE_TYPE:
         # If the passed object is an instance of an old-style class,
         # document its available methods instead of its value.
         object = object.__class__
     elif not (inspect.ismodule(object) or
               inspect.isclass(object) or
               inspect.isroutine(object) or
               inspect.isgetsetdescriptor(object) or
               inspect.ismemberdescriptor(object) or
               isinstance(object, property)):
         # If the passed object is a piece of data or an instance,
         # document its available methods instead of its value.
         object = type(object)
         desc += ' object'
     return title % desc + '\n\n' + text.document(object, name)


-- 
Pierre



More information about the NumPy-Discussion mailing list