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

Let black deal with line length #31

Closed
wants to merge 1 commit into from
Closed

Let black deal with line length #31

wants to merge 1 commit into from

Conversation

serl
Copy link

@serl serl commented Jun 13, 2021

Hello,
I just installed flake8 3.9.2, black 21.6b0, flake8-black 0.2.1 and Django 3.2.4 (latest versions).
Then I run black and I configured flake8 using the suggested configuration, but it doesn't spark with joy:

$ flake8
./test_project/settings.py:89:89: E501 line too long (91 > 88 characters)

Seems like sometimes black does not really respect its own line length limit, here's line 89:

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    # ...
]

My solution was to ask politely flake8 to mind its business and leave line lengths to black.
Here's a PR for it. Feel free to improve/change/correct/...

@peterjc
Copy link
Owner

peterjc commented Jun 13, 2021

I think black plans to divide overly long strings, which is how I usually see this happen.

However, unlike you, when this happens I want the E501 message.

@serl
Copy link
Author

serl commented Jun 13, 2021

I see your point.

So, how can I edit this line to pass both black and flake8?

@peterjc
Copy link
Owner

peterjc commented Jun 13, 2021

Ignore all E501, add the comment # noqa: E501 to this line, or break the line up - perhaps:

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation"
        ".UserAttributeSimilarityValidator",
    },
    # ...
]

Or maybe black likes this indentation?

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation"
                ".UserAttributeSimilarityValidator",
    },
    # ...
]

See also psf/black#2063 psf/black#1314 psf/black#1327 psf/black#2183 and --experimental-string-processing

@serl
Copy link
Author

serl commented Jun 13, 2021

Wow, thanks for all the details! I should have found all of this by myself 😞

Using black --experimental-string-processing, that's the result:

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": (
            "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
        ),
    },
    # ...
]

Which indeed satisfies both flake8 and black. Adding manually the parentheses (then running black without arguments) has the same result.

Now that I put E501 back, it complains about a very long comment I have somewhere else, which is of course out of the scope of black. So yes, this PR is rubbish, I'm closing it! 😆

@serl serl closed this Jun 13, 2021
@peterjc
Copy link
Owner

peterjc commented Jun 14, 2021

Glad to have helped, and thanks for sharing the black --experimental-string-processing output.

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

Successfully merging this pull request may close these issues.

2 participants