NumpyDoc:当我使用类型提示时,我可以省略DocString中的类型声明吗?

发布于 2025-02-13 19:17:33 字数 349 浏览 0 评论 0 原文

在功能签名中使用类型提示时,如果我遵守NumpyDoc样式,我是否也需要指定DocString中的参数类型?

def add(a: float, b: int) -> float:
    """

    Parameters
    ----------
    a
        Fist number.
    b : int
        Second number.

    Returns
    -------
    float
        Result of a + b

    """
    return a + b

参数部分中的 a 的定义是否足够?

When using type hints in the function signature, do I need to specify the parameter types in the docstring, too, if I were to comply with numpydoc style?

def add(a: float, b: int) -> float:
    """

    Parameters
    ----------
    a
        Fist number.
    b : int
        Second number.

    Returns
    -------
    float
        Result of a + b

    """
    return a + b

Is the defintion for a in the parameters section sufficient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝對不後悔。 2025-02-20 19:17:33

目前,我认为答案是 no ,如果您想使用 numpydoc python package 直接。有一个公开票: https://github.com/numpy/numpy/numpydoc/issues/196 <196 <196 <196 < /a>

我希望任何更改也会出现在 numpydoc 文档。

但是:渲染 DocStrings numpydoc -like 类型 hinted样式通过其他软件包。这是我发现的(部分通过 numpydoc 问题):

At present I think the answer is no if you want to use the numpydoc python package directly. There is an open ticket: https://github.com/numpy/numpydoc/issues/196

I expect any changes will also appear in numpydoc documentation.

However: rendering docstrings written in numpydoc-like type-hinted style might work via other packages. Here's what I've found (partly via that numpydoc issue):

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文