Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flake8 - line break before binary operator - how to fix it?

Tags:

python

flake8

I keep getting:

W503 line break before binary operator

Please help me fix my code, as I can't figure out what is wrong here:

def check_actionable(self, user_name, op, changes_table):
        return any(user_name in row.inner_text() and row.query_selector(
            self.OPS[op]) is not
                   None and row.query_selector(self.DISABLED) is not None for
                   row in changes_table)
like image 551
Tal Angel Avatar asked Jun 04 '26 07:06

Tal Angel


2 Answers

the other (imo better) alternative to ignore (which resets the default ignore list) is to use extend-ignore

by default both W503 and W504 are ignored (as they conflict and have flip-flopped historically). there are other rules which are ignored by default as well that you may want to preserve

extend-ignore = ABC123

ignore on the other hand resets the ignore list removing the defaults


disclaimer: I'm the current flake8 maintainer

like image 167
Anthony Sottile Avatar answered Jun 06 '26 23:06

Anthony Sottile


W503 rule and W504 rule of flake8 are conflicted to each other. I recommend you to add one of them into your .flake8's ignore list.

W503: line break before binary operator

W504: line break after binary operator

ignore = D400,D300,D205,D200,D105,D100,D101,D103,D107,W503,E712

The below code is prettified:

def check_actionable(self, user_name, op, changes_table):
    return any(user_name in row.inner_text() and
               row.query_selector(self.OPS[op]) is not None and
               row.query_selector(self.DISABLED) is not None for row in changes_table)

Some explanation on W503 and W504:

binary operator: +, -, /, and, or, ...

To pass W503, your code should be like this:

x = (1
     + 2)

To pass W504, your code should be like this:

x = (1 +
     2)
like image 34
hide1nbush Avatar answered Jun 06 '26 23:06

hide1nbush



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!