具有多种输入类型的Python文档字符串格式

时间:2018-11-20 08:44:37

标签: python docstring

我正在使用Google样式的python文档字符串格式。 有一个函数,输入参数可以是dict,list或string。 文档字符串中多种数据类型的格式是什么?

喜欢

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

1 个答案:

答案 0 :(得分:3)

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

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

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