30

我似乎无法弄清楚如何使用 Sphinx 记录异常。

我尝试了以下方法:

def some_funct():
    """
    :raises: ExceptionType: Some multi-line
        exception description.
    """


def some_funct():
    """
    :raises: ExceptionType, Some multi-line
        exception description.
    """


def some_funct():
    """
    :raises ExceptionType: Some multi-line
        exception description.
    """


def some_funct():
    """
    :raises:
        ExceptionType: Some multi-line
            exception description.
    """

斯芬克斯一直在说:

“字段列表结束时没有空行;意外取消缩进。”

那么如何摆脱该消息以及使用多行文档记录可能的多个异常的正确方法是什么?

4

4 回答 4

38

您可以使用反斜杠进行续行:

def some_funct():
    """
    :raises ExceptionType: Some multi-line \
        exception description.
    """

更新:

缩进似乎起作用而不是转义换行符:

def some_funct():
    """
    :raises ExceptionType: Some multi-line
        exception description.
    """
于 2013-04-12T14:04:57.967 回答
2
def some_funct():
    """
    My documentation, but watch the empty line below (necessary)

        :raise: Exception

            when status != my_status 
            | status <= max_status

注意:https ://pythonhosted.org/an_example_pypi_project/sphinx.html#full-code-example有一些不错的示例(不幸的是,不在多行异常中)

于 2014-10-08T10:56:07.960 回答
0

这给了我一些好东西。

您忘记了:异常名称之前

def some_funct():
    """
    :raise: 
        :IOException: a probleme occured
                      and it can't be passed
    """
于 2013-04-12T13:36:35.700 回答
0

我认为有一个样本不会让 Sphinx 抱怨:

def some_funct():
    """
    :raises: ExceptionType: Some multi-line
        exception description.

    """

(注意最后的空行)

于 2018-09-25T12:39:45.537 回答