Closed serl closed 3 years ago
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.
I see your point.
So, how can I edit this line to pass both black and flake8?
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 https://github.com/psf/black/issues/2063 https://github.com/psf/black/issues/1314 https://github.com/psf/black/issues/1327 https://github.com/psf/black/issues/2183 and --experimental-string-processing
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! 😆
Glad to have helped, and thanks for sharing the black --experimental-string-processing
output.
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:
Seems like sometimes black does not really respect its own line length limit, here's line 89:
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/...