让我们考虑以下示例:
from typing import Union
import numpy as np
class MyClass:
def __init__(self):
self._x = None
@property
def x(self) -> Union[float, np.ndarray]:
if len(self._x) == 1:
return self._x[0]
else:
return self._x
@x.setter
def x(self, value: Union[float, list, np.ndarray]):
self._x = np.atleast_1d(value)
关于如何正确记录上述代码的任何建议?我正在使用Sphinx
和numpydoc
。
非常感谢!
编辑:我意识到我的问题不是很清楚,所以我要补充几句。x
基本上,主要问题是如何记录作为float, list or array
输入和输出的事实float or array
。我在一些例子中看到这应该是getter
唯一的,我不知道我是否应该添加关键字Parameters
,Returns
或者它是否是更好的方法,因为我没有找到足够的答案(或者我只是想念他们)。