Google python style guide
说:
精细。在 生成器函数的文档字符串中使用“Yields:”而不是“Returns:”。
来自实例here采取:
def example_generator(n):
"""Generators have a ``Yields`` section instead of a ``Returns`` section.
Args:
n (int): The upper limit of the range to generate, from 0 to `n` - 1
Yields:
int: The next number in the range of 0 to `n` - 1
Examples:
Examples should be written in doctest format, and should illustrate how
to use the function.
>>> print [i for i in example_generator(4)]
[0, 1, 2, 3]
"""
for i in range(n):
yield i
请注意,这不是一个官方的Python编程风格指南。
如果你打算在conf.py
将它添加到的extensions
列表使用Yields
你需要利用sphinxcontrib-napoleon
扩展:
extensions = ['...', ..., 'sphinxcontrib.napoleon']
sphinxcontrib-napoleon
认识Yields
关键字among others上的文档字符串预处理步骤:
拿破仑是一个狮身人面像的扩展,使狮身人面像解析NumPy 和谷歌风格文档字符串 - 汗学院推荐的风格。
拿破仑是一个预处理器,它分析与NumPy和谷歌的风格 文档字符串,并把它们转换成新结构化前的狮身人面像 试图分析它们。这发生在中间步骤,而 Sphinx正在处理文档,所以它不会修改任何 实际源代码文件中的文档字符串。
我个人认为,使用Returns:
是非常好的,因为一个generator
基本上是function
的一个特例。
关闭到[文档字符串标签关于 '产量' 关键字(http://stackoverflow.com/questions/7652540/docstring-tag-for-yield-keyword ?RQ = 1)。 – alecxe
我不知道reST,但我的猜测是你会按照你记录任何其他“返回迭代器”函数的方式记录它。 yield的使用是一个实现细节。 – user2357112
是的,我知道其他问题是类似的,我想要一个特定于reST的答案,谢谢! – gatoatigrado