Dr. Strangelove
Dr. Strangelove

Reputation: 3328

W504 line break after binary operator

I have a condition that reads like:

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

flake8 complains about this line with the error message:

W504 line break after binary operator

When I move the operator around, it throws a different error:

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

W503 line break before binary operator

I tried multiple recommendations (e.g., this), but still, flake8 complains about the linebreak. The actual condition in my code is very long so I cannot put it in one line, also, it is the preference of my team to enclose long lines in () instead of using \.

Upvotes: 6

Views: 5967

Answers (2)

anthony sottile
anthony sottile

Reputation: 69934

you have set ignore = in your configuration -- you should use extend-ignore =

W504 and W503 conflict with each other (and are both disabled by default) -- by setting ignore you've re-enabled them. extend-ignore does not have this problem as it augments the default set of ignored codes


disclaimer: I'm the current flake8 maintainer

Upvotes: 16

Paras Gupta
Paras Gupta

Reputation: 294

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

This should resolve the issue.

Upvotes: -5

Related Questions