我正在按照numpydoc
style guide来记录我的代码,但是我找不到返回类实例的约定:
"""Create an index in the meilisearch API.
If the argument \`uid\` isn't passed in, it will be generated by meilisearch.
If the argument \`name\` isn't passed in, it will raise an error.
Parameters
----------
name: str
Name of the index
uid: str, optional
Unique identifier of the index
Raises
------
HTTPError
If no name is passed in as a parameter.
HTTPError
In case of any other error found here https://docs.meilisearch.com/references/#errors-status-code
Returns
-------
index
an instance of Index containing the information of the newly created index
"""
如您所见,在returns部分中,我返回Index的一个实例。
这是记录文件的方法吗?
提前致谢
最佳答案
从numpydoc style guide:
5.退货
返回值及其类型的说明。与“参数”部分相似,但每个返回值的名称是可选的。始终需要每个返回值的类型。
Returns
-------
int
Description of anonymous integer return value.
因此,对于您的示例,您将使用
Index
作为类型,以及一个可选名称:Returns
-------
index : Index
<some meaningful description here>
在这里,
index :
部分是可选的。关于python - 返回类实例时的Numpydoc样式约定,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59251348/