Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to generate pydoc for nested functions? [closed]

I'm looking for a way to generate documentation, pydoc on this case, for nested functions. Is this possible with pydoc? Is it possible with other tools?

For example:

"""
Module docstring.
"""

def foo(x):
    """
    Foo does something.
    """
    ...

    def bar(y):
        """
        Bar does something
        """
        ...

Generating pydoc with: pydoc -w -filename- will generate pydoc for the module and foo() but not for bar().

Normally this would be ok; the problem is that I'm trying to build a library for educational purposes, and documenting what happens inside the closure is specially helpful. I want to find a way to document it without having to expose the inner functions to the global scope.

like image 799
runw Avatar asked Nov 12 '22 21:11

runw


1 Answers

There is always the manual method:

"""
Module docstring.
"""

def foo(x):
    """
    Foo does something.
    N.B. Foo includes a local function bar() that does what bar does.
    """
    ...

    def bar(y):
        """
        Bar does something
        """
        ...

It is not automatic but it does mean that your students only get to see documentation on those private methods that you wish them to see.

like image 144
Steve Barnes Avatar answered Nov 14 '22 23:11

Steve Barnes