docstring-missing-yields (DOC402)
源自 pydoclint 代码检查器。
此规则不稳定且处于预览状态。使用需要 --preview 标志。
作用
检查包含 yield 语句但在文档字符串(docstring)中缺少 “Yields” 部分的函数。
为什么这不好?
缺少 “Yields” 部分表明文档不完整。
此规则不适用于抽象方法或仅 yield None 的函数。对于“存根函数”(stub functions)——即函数体仅包含 pass、...、raise NotImplementedError 或类似代码的函数,此规则也会被忽略。
示例
def count_to_n(n: int) -> int:
"""Generate integers up to *n*.
Args:
n: The number at which to stop counting.
"""
for i in range(1, n + 1):
yield i
建议改为
def count_to_n(n: int) -> int:
"""Generate integers up to *n*.
Args:
n: The number at which to stop counting.
Yields:
int: The number we're at in the count.
"""
for i in range(1, n + 1):
yield i