0

How to generate automatically docs for the c_nested function?

Background: I do code documentation for other developers and I would like to automatically generate a summary of all class methods included nested functions with short description (docstring).

When I run help(A) on class A I get:

Help on class A in module __main__:

class A(builtins.object)
 |  A(a)
 |  
 |  doc A
 |  
 |  Methods defined here:
 |  
 |  __init__(self, a)
 |      Initialize self.  See 
 |  
 |  b_method(self)
 |      doc b_method

Requested output: c_nested() with docstring: (Docs could be printed event with script, it doesn't need to be printed with pydoc help.)

Help on class A in module __main__:

class A(builtins.object)
 |  A(a)
 |  
 |  doc A
 |  
 |  Methods defined here:
 |  
 |  __init__(self, a)
 |      Initialize self.  See 
 |  
 |  b_method(self)
 |      doc b_method
 |
 |           c_nested()
 |                doc c_nested

Class example:

class A:
    """ doc A """
    def __init__(self,a):
        self.a = a

    def b_method(self):
        """ doc b_method """

        def c_nested():
            """doc  c_nested """
            pass

        return c_nested()
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Dan
  • 437
  • 7
  • 24

1 Answers1

1

Local functions are not publicly visible, so their docstring won't be included in the help.

If you want the function to be shown in the help, make it a module-level function or a method of the class.

See also Are docstrings for internal functions (python) necessary?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • thanks for info, but it will not solve the problem, I'm creating code documentation for other developers and I would like to generate automatically summary of all class methods included nested functions. – Dan Jan 23 '21 at 14:37
  • Nested functions cannot be called, why would you want to include them in your public documentation? – Maximilian Hils Jan 24 '21 at 21:22