NumpyDoc:当我使用类型提示时,我可以省略DocString中的类型声明吗?
在功能签名中使用类型提示时,如果我遵守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
的定义是否足够?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,我认为答案是 no ,如果您想使用
numpydoc
python
package 直接。有一个公开票: https://github.com/numpy/numpy/numpydoc/issues/196 <196 <196 <196 < /a>我希望任何更改也会出现在
numpydoc
文档。但是:渲染
DocStrings
用numpydoc
-like类型
hinted样式通过其他软件包。这是我发现的(部分通过numpydoc
问题):numpydoc-style
mkdocs
通过mkdocstrings
QUARTO
通过Quartodoc
(请参阅 nofollow noreferrer“> resucty-instem-insus-usess-insus-insus-insus-insus-indy-type-type-type-nottation )sphinx
通过 sphinx-autodoc-typehintsAt 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/196I expect any changes will also appear in
numpydoc
documentation.However: rendering
docstrings
written innumpydoc
-liketype
-hinted style might work via other packages. Here's what I've found (partly via thatnumpydoc
issue):griffe
is adocstring
parser that supports thisnumpydoc-style
. That's used by:MkDocs
viamkdocstrings
quarto
viaquartodoc
(see results-using-type-annotation)Sphinx
viasphinx-autodoc-typehints