跳到内容

docstring-starts-with-this (D404)

源自 pydocstyle 代码检查器。

作用

检查以 This 开头的文档字符串。

为什么这不好?

PEP 257 建议,为了保持一致性,文档字符串的第一行应以祈使语气编写。

提示:要以祈使语气重写文档字符串,请将第一行措辞为命令形式。

此规则可能不适用于所有项目;其适用性是一个约定问题。默认情况下,在使用 numpy 约定启用此规则,而在使用 googlepep257 约定禁用此规则。

示例

def average(values: list[float]) -> float:
    """This function returns the mean of the given values."""

建议改为

def average(values: list[float]) -> float:
    """Return the mean of the given values."""

Options (选项)

参考