-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Line too long: Long from import #4177
Comments
Could you give a sample of the code that Black is not formatting correctly? |
Something like: from src.pkg.core.application.another_pkg.yet_another_pkg.this_is_getting_long.some_file_with_a_long_name import (
Something,
) Is not formatted, and when breaking it manually like: from src.pkg.core.application.another_pkg.yet_another_pkg. \
this_is_getting_long.some_file_with_a_long_name import (
Something,
)
I'll add this to the original question. (I edited the examples to reflect my current config of line length being 80) |
Thanks. The import issue is new, but I'm not sure we'd want to fix it, since the proposed formatting is ugly and there's a good chance it will conflict with import formatting tools. The long triple-quoted string (not a comment) is essentially #1617. I don't think we'll fix that either, as the line breaks in a triple-quoted string may be significant, so that decision is better left to the user. As a workaround, I'd suggest disabling flake8's line length rules. Black should be responsible for formatting, and you don't get much additional value out of another tool complaining about formatting minutiae. |
I'll bring this up with the team, thanks. |
Describe the bug
I originally posted on SO here.
I have a python project with Flake8 and Black installed. I'm using VSCode, with the following workspace configuration in
settings.json
:"black-formatter.args": ["--line-length=80"],
. I also tried:"black-formatter.args": ["--line-length, "80"],
This arg is also manually addedin the settings UI for the user, WSL, and workspace.
I also tried running black in the terminal with the arg like this:
black --line-length=80 conftest.py
The output:
When I manually break the long line, black actually undoes the change. I can't just configure the project to ignore this error, because this is a shared project and this style has to be enforced.
I'm using WSL2 inside Windows 11, python version 3.11.5. I'm also using poetry version 1.7.1. Any help is appreciated.
To Reproduce
Unfortunately I can't post exact lines of code since this is for work, but any lines above 100 characters cause this issue, but
something like:
Is not formatted, and when breaking it manually like:
Black reverts the line break.
I've also seen this happen with comments, though line breaks arent reverted in this case. Flake8 does complain about long comments at least for me:
Black should break long lines (according to the config I used, any line > 80 characters), or at least not revert changes made to manually break lines.
Environment
Windows 11, WSL2, python 3.11.5, poetry 1.7.1
The text was updated successfully, but these errors were encountered: