【问题标题】:Python Google docstring format: more than one type for argument?Python Google 文档字符串格式:不止一种类型的参数?
【发布时间】:2018-11-20 08:44:36
【问题描述】:

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

喜欢

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

【问题讨论】:

    标签: python docstring


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2017-09-28
      • 2023-03-22
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      相关资源
      最近更新 更多