我似乎无法弄清楚如何使用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.
"""
斯芬克斯一直说“字段列表没有空行结束;出乎意料的意外。”那么如何摆脱这条消息以及用多行文档记录可能的多个异常的正确方法是什么?
答案 0 :(得分:24)
您可以使用反斜杠进行续行:
def some_funct():
"""
:raises ExceptionType: Some multi-line \
exception description.
"""
<强>更新强>
缩进似乎有效,而不是转义换行符:
def some_funct():
"""
:raises ExceptionType: Some multi-line
exception description.
"""
答案 1 :(得分: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有一些不错的样本(不幸的是不在多行异常上)
答案 2 :(得分:0)
这给了我一些不错的东西。
您忘记了:
在例外名称之前
def some_funct():
"""
:raise:
:IOException: a probleme occured
and it can't be passed
"""
答案 3 :(得分:0)
我认为有一个样本不会让Sphinx抱怨:
def some_funct():
"""
:raises: ExceptionType: Some multi-line
exception description.
"""
(请注意末尾的空白行)