Python sphinx 文档字符串信息字段列表是否需要py:method?

Python sphinx 文档字符串信息字段列表是否需要py:method?,python-sphinx,Python Sphinx,我正在使用sphinx apidoc从Python文档字符串收集文档 为了获得格式化的参数,返回,引发和其他sphinx文档部分,似乎我需要放置。。py:method::或其他类似的域表示形式,如这个普通类所示: class Message(object): """ .. py:class:: Base class representing a message. """ DEFAULT_PRIORITY = 5 def __init__(

我正在使用sphinx apidoc从Python文档字符串收集文档

为了获得格式化的
参数
返回
引发
和其他sphinx文档部分,似乎我需要放置
。。py:method::
或其他类似的域表示形式,如这个普通类所示:

class Message(object):
    """
    .. py:class::
       Base class representing a message.
    """

    DEFAULT_PRIORITY = 5

    def __init__(self):
        """
        .. py:method::
           Constructor.
        """
        self.priority = Message.DEFAULT_PRIORITY

    def set_priority(self, priority):
        """
        .. py:method::
           Set the message priority.

        :param int priority: The new message priority.
        :return: The old message priority.
        :rtype: int
        :raise TypeError: The given priority is not an int.
        """
        if not isinstance(priority, int):
            raise TypeError
        old_priority = priority
        self.priority = priority
        return old_priority
没有
。。py:method
等。参数、返回等在一行中未格式化


这些是必要的吗?

不,是
。。py:方法
不需要零件。所需的是一条新行,将描述与
:param
和其他块分开,如下所示:

class Message(object):
    """
    Base class representing a message.
    """

    DEFAULT_PRIORITY = 5

    def __init__(self):
        """
        Constructor.
        """
        self.priority = Message.DEFAULT_PRIORITY

    def set_priority(self, priority):
        """
        Set the message priority.

        :param int priority: The new message priority.
        :return: The old message priority.
        :rtype: int
        :raise TypeError: The given priority is not an int.
        """
        if not isinstance(priority, int):
            raise TypeError
        old_priority = priority
        self.priority = priority
        return old_priority