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

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) 
1

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

2

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) 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like