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 and flake8 can't agree on line length limit #1314

Closed
jaraco opened this issue Mar 24, 2020 · 9 comments
Closed

Black and flake8 can't agree on line length limit #1314

jaraco opened this issue Mar 24, 2020 · 9 comments
Labels
F: linetoolong Black makes our lines too long R: duplicate This issue or pull request already exists T: bug Something isn't working T: style What do we want Blackened code to look like?

Comments

@jaraco
Copy link
Contributor

jaraco commented Mar 24, 2020

Given this code, flake8 (correctly) errors that the line is longer than the declared line length, which is 88 to match the expectation of black. If I correct the syntax to satisfy flake8, black starts to fail, such as in this commit.

Is there a way for black and flake8 to get along?

@jaraco jaraco added the T: bug Something isn't working label Mar 24, 2020
@kubasikus
Copy link

kubasikus commented Mar 27, 2020

I've recently been trying to use black in stuff I do, and i found that setting flake8 to --max-line-length=~95-100 lets you live in relative peace. Black will sometimes overflow, but not by much. If it does overflow by a lot, it might be because it cannot split string (yet). So you will have to fix that manually - and flake will let you know.

@EgZvor
Copy link

EgZvor commented Apr 19, 2020

How do you format this part manually to satisfy line length requirement?

swhmirror pushed a commit to SoftwareHeritage/swh-loader-mercurial that referenced this issue Apr 29, 2020
@retnikt
Copy link

retnikt commented Jun 2, 2020

I have found the easiest way is to disable the relevant Flake8 errors and just let Black handle them - you can use black --check to add to your linting scripts.

@jaraco
Copy link
Contributor Author

jaraco commented Jun 3, 2020

I'd be okay with that as a resolution if that were the recommendation of the flake8 team. I'm a little uneasy with accepting that outcome if it's one project deprecating another.

@davips
Copy link

davips commented Jun 4, 2020

I've recently been trying to use black in stuff I do, and i found that setting flake8 to --max-line-length=~95-100 lets you live in relative peace. Black will sometimes overflow, but not by much. If it does overflow by a lot, it might be because it cannot split string (yet). So you will have to fix that manually - and flake will let you know.

Please keep it that way, not breaking strings is a feature! Sometimes we all have strings which are not interesting at all to be read or changed. One can easily manually break the exceptionally interesting ones. If you are curious, e.g. encoders can have alphabets with hundreds of columns in a string. Error messages etc. Moreover, interpolation and line breaks together are a hell to edit and keep it formatted.

@jaraco
Copy link
Contributor Author

jaraco commented Jun 4, 2020

I don't think anything in my example suggests to break string lengths. The longest string in that block is 30 chars.

@JelleZijlstra JelleZijlstra added F: linetoolong Black makes our lines too long T: style What do we want Blackened code to look like? labels May 30, 2021
@JelleZijlstra
Copy link
Collaborator

Duplicate of #413.

The sample code is:

            '/': {
                'tools.auth_basic.on': True,
                'tools.auth_basic.realm': 'RecaptureDocs admin',
                'tools.auth_basic.checkpassword': cherrypy.lib.auth_basic.checkpassword_dict(
                    dict(admin='g0tch4-h4x0r',)
                ),
            },

@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Jan 29, 2022
@kwk
Copy link

kwk commented Feb 13, 2023

Duplicate of #413.

The sample code is:

            '/': {
                'tools.auth_basic.on': True,
                'tools.auth_basic.realm': 'RecaptureDocs admin',
                'tools.auth_basic.checkpassword': cherrypy.lib.auth_basic.checkpassword_dict(
                    dict(admin='g0tch4-h4x0r',)
                ),
            },

@JelleZijlstra I don't see the similarity of #413 and #1314 . The latter is for flake8 and black to get along but the first seems to be for broken formatting.

@JelleZijlstra
Copy link
Collaborator

The reason they don't "get along" is that Black doesn't split a line that is too long, so the fix is to make it so Black does split the line, which is what #413 is about. If there's anything else that this issue would cover, I'm not seeing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linetoolong Black makes our lines too long R: duplicate This issue or pull request already exists T: bug Something isn't working T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

8 participants