【问题标题】:Verify code and documentation match验证代码和文档匹配
【发布时间】:2016-12-10 02:45:43
【问题描述】:

使用 Sphinx 扩展 NumpyDoc,是否有某种方法可以自动确保文档与其记录的代码匹配?

例如,由于拼写错误,以下文档与代码不匹配:

def myfunc(apples, bears):
"""
    Parameters
    ----------
    apples : int
        The number of apples.
    beards : int
        The number of bears to eat the apples.
"""

Sphinx 或 NumpyDoc 可以使这成为错误吗?

【问题讨论】:

    标签: python python-sphinx numpydoc


    【解决方案1】:

    这是 NumpyDoc 或 Sphinx 内置的,但可以使用 NumpyDoc's scraping abilities。这是完成所需功能的代码 sn-p:

    import inspect
    
    from numpydoc.docscrape import FunctionDoc
    
    def myfunc(apples, bears):
        """
            Parameters
            ----------
            apples : int
                The number of apples.
            beards : int
                The number of bears to eat the apples.
        """
    
    doc = FunctionDoc(myfunc)
    argspec = inspect.getargspec(myfunc)
    
    # check for basic spelling errors
    for a_i, arg in enumerate(argspec.args):
        if arg != doc["Parameters"][a_i][0]:
            print("%s != %s" %(arg, doc["Parameters"][a_i][0]))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 2017-03-16
      相关资源
      最近更新 更多