Python Google 文档字符串格式:不止一种类型的参数?

use*_*219 5 python docstring

我正在使用 Google 风格的 python 文档字符串格式。有一个函数,输入参数可以是字典、列表或字符串。docstring中多种数据类型的格式是什么?

喜欢

Args:
    input (str, list, dict): input of this function
Run Code Online (Sandbox Code Playgroud)

aru*_*ska 7

正如Sphinx 1.5 文档中所述描述这种格式,支持 PEP 484 类型注释。

PEP 484 指定了适合于参数接受类型有限集的情况的联合类型。在您的示例中,它将是:

Args:
    input (Union[str, list, dict]): input of this function
Run Code Online (Sandbox Code Playgroud)