如何指定返回类型并在单行ReST文档字符串中描述返回值?

时间:2018-01-04 12:57:21

标签: python restructuredtext docstring

我知道我可以缩写以下ReST docstring

"""
:type flag: bool
:param flag: new value for the flag
"""

作为

"""
:param bool flag: new value for the flag
"""

我可以用类似的方式缩写以下内容吗?

"""
:rtype: bool
:returns: new value of flag
"""

2 个答案:

答案 0 :(得分:0)

是。 Sphinx中的Python域支持此选项和其他信息字段列表选项。见http://www.sphinx-doc.org/en/stable/domains.html#info-field-lists

修改即可。下面的文档复制面食。

  

在Python对象描述指令中,具有这些字段的reST字段列表可以很好地识别和格式化:

     

- 剪断 -

     
      
  • returnsreturn:返回值的说明。
  •   
  • rtype:返回类型。如果可能,创建一个链接。
  •   
     

- 剪断 -

    :return: the message id
    :rtype: int

returnsreturn功能相同。

或者你的意思完全是什么?

答案 1 :(得分:0)

这是不可能的。必须在 / home/ user/ X/ scripy.py second_scripy.py Y/ a.c b.c user@user:~$ pwd /home/ user@user:~$ python user/X/script.py returns中指定说明,并在return中指定返回类型。不允许将这些合并为一行。