繁体   English   中英

Python:docstrings和type annotations

[英]Python: docstrings and type annotations

有这样的功能:

def foo(x: int) -> float:
    return float(x)

我想使用类似NumPy的文档字符串,如下所示:

def foo(x: int) -> float:
    """
    Parameters
    ----------
    x
        Input parameter

    Returns
    -------
    The output value.
    """
    return float(x)

注意:

  • 我不想再次指定参数类型。
  • 我不想再次指定返回类型。
  • 我希望该扩展能够读取带注释的类型(并在生成的HTML文档中编写它们)。

是否有支持它的Sphinx扩展? 你会推荐另一种语法吗?

标准扩展名是autodoc Napoleon扩展支持Google和NumPy风格的文档字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM