W504 二元运算符后换行

W504 line break after binary operator

我的条件如下:

ok = (not a > 10 and
      not b < 10 and
      not c > 99 and
      d == 99)

flake8 抱怨此行并显示错误消息:

W504 line break after binary operator

当我四处移动运算符时,它抛出一个不同的错误:

ok = (not a > 10
      and not b < 10
      and not c > 99
      and d == 99)

W503 line break before binary operator

我尝试了多个建议(例如,this),但 flake8 仍然抱怨换行符。我的代码中的实际条件很长,所以我不能把它放在一行中,而且,我的团队更喜欢将长行放在 () 中而不是使用 \.

ok = (
    not a > 10 and
    not b < 10 and
    not c > 99 and
    d == 99
)

这应该可以解决问题。

您在配置中设置了 ignore = -- 您应该使用 extend-ignore =

W504W503 相互冲突(默认情况下均禁用)——通过设置 ignore 您已重新启用它们。 extend-ignore 没有这个问题,因为它增加了默认的忽略代码集


免责声明:我是当前的 flake8 维护者