Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

black not producing flake8 compatible code #113

Closed
bhearsum opened this issue Apr 5, 2018 · 3 comments
Closed

black not producing flake8 compatible code #113

bhearsum opened this issue Apr 5, 2018 · 3 comments

Comments

@bhearsum
Copy link

bhearsum commented Apr 5, 2018

Howdy! Sorry you're having trouble. To expedite your experience,
provide some basics for me:

Operating system: Linux
Python version: 3.6.3
Black version: 18.4a0
Does also happen on master: yes

I've run black on a codebase that is already flake8 compatible, and it ends up reformatting things in such a way that it fails a whole bunch of flake8 checks. For example:

➜  balrog git:(black2) ✗ flake8 auslib scripts uwsgi *.py client
➜  balrog git:(black2) ✗ black -l 120 --fast auslib scripts uwsgi *.py agent client
 ➜  balrog git:(black2) ✗ flake8 auslib scripts uwsgi *.py client
auslib/db.py:21:121: E501 line too long (162 > 120 characters)
from auslib.util.rulematching import matchChannel, matchVersion, matchBuildID, matchMemory, matchSimpleExpression, matchCsv, matchLocale, matchBoolean, matchRegex
                                                                                                                        ^
auslib/db.py:1779:17: W503 line break before binary operator
                & ((self.buildTarget == updateQuery["buildTarget"]) | (self.buildTarget == null()))
                ^
auslib/db.py:1780:17: W503 line break before binary operator
                & ((self.headerArchitecture == updateQuery["headerArchitecture"]) | (self.headerArchitecture == null()))
                ^
auslib/db.py:2061:21: W503 line break before binary operator
                    | (self.db.releases.name == self.db.rules.fallbackMapping)
                    ^
auslib/log.py:9:121: E501 line too long (134 > 120 characters)
log_format = "%(asctime)s - %(levelname)s - PID: %(process)s - Request: %(requestid)s - %(name)s.%(funcName)s#%(lineno)s: %(message)s"

One of the diffs that seems to be causing some of the issues is:

-                ((self.product == updateQuery['product']) | (self.product == null())) &
-                ((self.buildTarget == updateQuery['buildTarget']) | (self.buildTarget == null())) &
-                ((self.headerArchitecture == updateQuery['headerArchitecture']) | (self.headerArchitecture == null()))
+                ((self.product == updateQuery["product"]) | (self.product == null()))
+                & ((self.buildTarget == updateQuery["buildTarget"]) | (self.buildTarget == null()))
+                & ((self.headerArchitecture == updateQuery["headerArchitecture"]) | (self.headerArchitecture == null()))

(And many more - it looks like around ~150 total flake8 failures).

This can be reproduced locally by cloning https://github.com/mozilla/balrog, changing tox.ini's max-line-length to 120 (I'm planning to change the line length at the same time as reformatting with Black), and running flake8 before & after running black.

@zsol
Copy link
Collaborator

zsol commented Apr 5, 2018

I think this is because since #21 a linebreak is introduced before a binary operator to conform to PEP8. I would ignore W503 :)

I'll defer to someone else for E501

@ambv
Copy link
Collaborator

ambv commented Apr 5, 2018

For "line too long", just add organizing parentheses to your assignment and it will do the correct thing. Next version is going to do that automatically.

Yeah, disable W503, it's wrong.

@bhearsum
Copy link
Author

bhearsum commented Apr 9, 2018

Sounds like this is mostly me misunderstanding the expected state. Thanks for the replies.

@bhearsum bhearsum closed this as completed Apr 9, 2018
jstvz added a commit to SFDO-Tooling/CumulusCI that referenced this issue Nov 20, 2018
kvikshaug added a commit to DD-DeCaF/metanetx that referenced this issue Jun 12, 2019
kvikshaug added a commit to DD-DeCaF/cookiecutter-flask-microservice that referenced this issue Jun 12, 2019
dhalperi added a commit to intentionet/netconan that referenced this issue Jan 20, 2021
They disagree with black, and the Internet says that Black is right.

psf/black#113
psf/black#315
dhalperi added a commit to intentionet/netconan that referenced this issue Jan 20, 2021
Have to ignore flake8 E203 and W503 - they disagree with black, and the Internet says that black is right.

psf/black#113
psf/black#315
sfraint pushed a commit to intentionet/netconan that referenced this issue Apr 27, 2021
Have to ignore flake8 E203 and W503 - they disagree with black, and the Internet says that black is right.

psf/black#113
psf/black#315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants