reStructuredText 文档字符串中的多个 return 值 (Python 3)

Multiple return values in reStructuredText doc strings (Python 3)

我用 reStructuredText 文档字符串记录了我所有的 Python 函数。不幸的是,我缺少一种描述 多个 return 值 的方法。我找到的所有标准参考资料都只涉及一个 return 值的情况,例如 Sphinx-Doc or Realpython.

示例:

def get_linear_function_2d(p1, p2):
    """
    Compute 2d linear function in slope-intercept form
       y = mx + n
    based on two coinciding (x,y) points.

    :param tuple p1: (x,y) tuple describing one point that lies on the line
    :param tuple p2: (x,y) tuple describing another point that lies on the line (has to differ in x)
    <START OF ISSUE: How to document?>
      :return float: slope (m)
      :return float: y-intercept (n)
    <END OF ISSUE>
    """
    assert isinstance(p1, tuple) and len(p1) == 2 and all([isinstance(val, (int, float)) for val in p1])
    assert isinstance(p2, tuple) and len(p2) == 2 and all([isinstance(val, (int, float)) for val in p2])
    assert p1[0] != p2[0]
    m = (p2[1] - p1[1]) / (p2[0] - p1[0])
    n = p1[1] - m * p1[0]
    return m, n

备注:此问题已针对Python2提出,见How to document multiple return values using reStructuredText in Python 2?

但是:

Python 在技术上没有多个 return 值。 Python 中的 return 语句中的逗号分隔值仅表示您正在 returning 单个元组值。将其记录为元组。