Sphinx文档中的Python模块参考

Fun*_*ayu 3 python python-sphinx

让我们考虑以下功能:

def format_send_event(self, message_identifier, payload=""):
    """
    Format a SendEvent.

    :param message_identifier: Message identifier (defined in the :py:module:`MyModule.constants` file).
    :type message_identifier: int
    :param payload: Payload of the message.
    :type payload: str
    """
    # Do something
Run Code Online (Sandbox Code Playgroud)

使用sphinx-build进行编译时,出现以下错误:

...MyModule/handlers.py:docstring of MyModule.handlers.MyClass.format_send_event:3: ERROR: Unknown interpreted text role "py:module".
Run Code Online (Sandbox Code Playgroud)

看起来sphinx-builder无法理解该标签:py:module:

在Sphinx中用于引用模块的标签是什么?

Mic*_*son 5

根据文档,您应该使用:py:mod:交叉引用。

通常,标签的较短版本似乎用于交叉引用,而较长的名称用于文档记录。