返回类的实例时的Numpydoc样式约定

问题描述 投票:0回答:1

我正在按照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  
"""

在返回部分,如您所见,我返回Index的一个实例。这是记录文件的方法吗?

提前感谢

python numpydoc
1个回答
1
投票

numpydoc style guide

5。返回返回值及其类型的说明。与Parameters部分相似,不同之处在于每个返回值的名称都是可选的。始终需要每个返回值的类型。

Returns
-------
int
    Description of anonymous integer return value.

因此,在您的示例中,您将使用Index作为类型,以及可选名称:

Returns
-------
index : Index
    <some meaningful description here>

这里index :部分是可选的。

© www.soinside.com 2019 - 2024. All rights reserved.