跳到内容

too-many-boolean-expressions (PLR0916)

源自 Pylint 代码检查工具。

此规则不稳定且处于预览状态。使用需要 --preview 标志。

作用

检查 if 语句中过多的布尔表达式。

默认情况下,此规则允许最多 5 个表达式。这可以使用 lint.pylint.max-bool-expr 选项进行配置。

为什么这不好?

具有许多布尔表达式的 if 语句更难理解和维护。考虑将布尔表达式或其任何子表达式的结果赋值给变量。

示例

if a and b and c and d and e and f and g and h:
    ...

Options (选项)