[英]Is there a Sphinx reST Python docstring field for yields?
I'm trying to use reST-style docstrings, ie我正在尝试使用 reST 样式的文档字符串,即
def foo(bar):
"""a method that takes a bar
:param bar: a Bar instance
:type bar: Bar
Is there a standard way to document yields
?有没有标准的方法来记录
yields
? I looked at http://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#info-field-lists , a-la this question [ Using javadoc for Python documentation ], but no luck.我查看了http://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#info-field-lists ,a-la 这个问题 [ Using javadoc for Python documentation ],但没有运气。 I'm imagining something like,
我在想象这样的事情,
:yields: transformed bars
:yield type: Baz
Thanks!谢谢!
Python 3.5 Iterator[]
annotation Python 3.5
Iterator[]
注解
They offer a standardized Iterator[]
syntax for this as documented at: https://docs.python.org/3/library/typing.html#typing.Generator他们为此提供了标准化的
Iterator[]
语法,如文档所述: https : //docs.python.org/3/library/typing.html#typing.Generator
Before Python 3, I recommend that you use this syntax to make it easier to port later on:在 Python 3 之前,我建议您使用此语法以便以后更容易移植:
from typing import List
def f():
"""
:rtype: Iterator[:class:`SomeClass`]
"""
yield SomeClass()
And after Python 3, use https://pypi.python.org/pypi/sphinx-autodoc-annotation with syntax:在 Python 3 之后,使用https://pypi.python.org/pypi/sphinx-autodoc-annotation的语法:
from typing import Iterator
def f() -> Iterator[SomeClass]:
yield SomeClass()
I have reviewed the other answer and it doesn't in my opinion answer the question.我已经查看了另一个答案,在我看来它并没有回答这个问题。
The way to document a generator, although not the best, is by using :return
as in the rest of the docs.记录生成器的方法虽然不是最好的,但与其他文档一样使用
:return
。 Use the description to give notice that it is a generator.使用描述来通知它是一个生成器。
Yields from Google/Numpy style docs convert yields to return clauses.来自 Google/Numpy 风格文档的 Yields 将 yields 转换为 return 子句。
https://bitbucket.org/RobRuana/sphinx-contrib/src/a06ae33f1c70322c271a97133169d96a5ce1a6c2/napoleon/sphinxcontrib/napoleon/docstring.py?at=default&fileviewer=file-view-default#docstring.py-678:680 https://bitbucket.org/RobRuana/sphinx-contrib/src/a06ae33f1c70322c271a97133169d96a5ce1a6c2/napoleon/sphinxcontrib/napoleon/docstring.py?at=default&fileviewer=doc8.py6default6#
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.