简体   繁体   English

如何自动生成包含嵌套函数的文档字符串?

[英]How to automatically generate docstrings including nested functions?

How to generate automatically docs for the c_nested function?如何为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).背景:我为其他开发人员编写代码文档,我想自动生成所有 class 方法的摘要,包括带有简短描述(文档字符串)的嵌套函数。

When I run help(A) on class A I get:当我在 class A上运行help(A)时,我得到:

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.)请求的 output: c_nested() with docstring: (文档可以用脚本打印事件,不需要用 pydoc 帮助打印。)

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 示例:

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()

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.如果您希望 function 在帮助中显示,请将其设为模块级 function 或 class 的方法。

See also Are docstrings for internal functions (python) necessary?另请参阅是否需要内部函数 (python) 的文档字符串?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Python 文档字符串自动生成 GitHub Wiki 文档 - Automatically Generate GitHub Wiki Documentation from Python Docstrings Doxygen for Python:如何为嵌套函数生成文档 - Doxygen for Python: How to generate documentation for nested functions 如何自动链接到Sphinx中的ReST文档字符串中的参数类型? - How do I automatically link to a parameter type in ReST docstrings in Sphinx? 如何使用 pipetools 为以函数范式编写的函数编写文档字符串 - How to write docstrings for functions written in functional paradigm using pipetools 有没有一种方法可以即时生成IPython文档字符串? - Is there a way to generate IPython docstrings on the fly? 传送某些python函数的文档字符串 - Conveying docstrings for certain python functions 如何使用重复生成所有排列/使函数嵌套的 x 数量 - How to generate all permutations with repetitions /make x amount of nested for functions 在python中,如何打印导入模块中定义的所有函数的文档字符串,而无需导入模块本身导入的函数? - In python, how to print the docstrings of all functions defined in an imported module, without the functions that the imported module itself imported? 如何编写有意义的文档字符串? - How to write meaningful docstrings? Python元编程:自动生成成员函数 - Python metaprogramming: automatically generate member functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM