Sphinx无法处理类定义中的函数赋值

2024-07-01 07:49:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Sphinx以及autodoc和numpydoc扩展来生成一个相当复杂的包的文档。我在自动生成中遇到了一个问题:

假设我有一个包含两个模块calculator.pymath.py的包。你知道吗

calculator.py内部,我定义了一个类,它将math.py模块中的一个函数作为标准变量分配:

class Calculation(object):
    def some_calculation(some_variable,calculate=math.multiplication)

在我的sphinx文档中,我使用类似于

.. autoclass:: some_package.calculator.Calculation
    :members:

在我的文档中,函数现在显示为指针,而不是名称:

some_calculation(some_variable,calculate=<function multiplication at 0x2b8882ef7f50>)

如果是这样的话,我可以改变Sphinx的配置,这样我的输出看起来像:

some_calculation(some_variable,calculate=math.multiplication) 

什么?你知道吗


Tags: 模块函数文档pysphinxmathsomevariable
1条回答
网友
1楼 · 发布于 2024-07-01 07:49:12

将docstring添加到some_calculation,其中第一行是您想要的签名:

class Calculation(object):
    def some_calculation(self, some_variable, calculate=math.multiplication):
        """some_calculation(some_variable, calculate=math.multiplication)

           More text...
        """
        ...

引用:http://sphinx-doc.org/ext/autodoc.html#confval-autodoc_docstring_signature

相关问题 更多 >

    热门问题