返回多个值的 python 文档字符串约定是什么?

What is the python docstring convention for returning multiple values?

假设我有一个函数return有多个值

import numpy as np
def add_and_raisepower(x, y):
    """
    1) Add inputs **x** and **y** and return the result.

    2) Raise **x** to the power of **y**, multiply this
    result by an array of one's and return the result.

    :type x: float
    :param x: The first input number

    :type y: float
    :param y: The second input number

    :rtype val1: float
    :rtype val2: numpy.array(float)
    """

    val1 = x + y
    val2 = np.ones(100)*(x**y)

    return val1, val2

我担心的是文档字符串中的 :rtype: 注释;如果函数 return 有多个值,如本例所示,:rtype: 应该如何写入文档字符串(根据 PEP-8)?

通常对于 return 只有一个值的函数,:rtype: 会写成类似

"""
...

:rtype: int
"""

未指定 returned 变量名因为它无关紧要,因为只有一个 return 值。

我明白理想情况下我应该尝试将我的函数分解成更简单的函数,这对于上面的 add_and_raisepower 来说当然是可能的,但是我只是用它作为一个玩具示例来说明这个问题。

在这种情况下,结果每次都是一个元组。像这样写下来:

:rtype: (float, numpy.array(float))