docstring-extraneous-returns (DOC202)
源自 pydoclint 代码检查器。
此规则不稳定且处于预览状态。使用需要 --preview
标志。
作用
检查函数文档字符串中是否存在不必要的“Returns”部分。
为什么这不好?
没有显式 return
语句的函数不应该在其文档字符串中包含“Returns”部分。
此规则不适用于抽象方法。 对于“存根函数”也会被忽略:即函数体仅包含pass
、...
、raise NotImplementedError
或类似内容。
示例
def say_hello(n: int) -> None:
"""Says hello to the user.
Args:
n: Number of times to say hello.
Returns:
Doesn't return anything.
"""
for _ in range(n):
print("Hello!")
建议改为