Python Google 文档字符串格式:参数有多种类型?

Python Google docstring format: more than one type for argument?

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

喜欢

Args:
    input (str, list, dict): input of this function

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

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

Args:
    input (Union[str, list, dict]): input of this function