过度缩进 (D208)
源自 pydocstyle 代码检查器。
修复总是可用的。
作用
检查过度缩进的文档字符串。
为什么这不好?
PEP 257 建议文档字符串应缩进到与其起始引号相同的级别。 为保持一致性,请避免过度缩进文档字符串。
示例
def sort_list(l: list[int]) -> list[int]:
"""Return a sorted copy of the list.
Sort the list in ascending order and return a copy of the result using the
bubble sort algorithm.
"""
建议改为
def sort_list(l: list[int]) -> list[int]:
"""Return a sorted copy of the list.
Sort the list in ascending order and return a copy of the result using the bubble
sort algorithm.
"""
格式化器兼容性
我们不建议将此规则与 格式化程序 一起使用。格式化程序强制执行一致的缩进,使该规则变得多余。