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

Line too long: Long from import #4177

Open
marianatuma opened this issue Jan 26, 2024 · 4 comments
Open

Line too long: Long from import #4177

marianatuma opened this issue Jan 26, 2024 · 4 comments
Labels
F: linetoolong Black makes our lines too long T: bug Something isn't working

Comments

@marianatuma
Copy link

marianatuma commented Jan 26, 2024

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:

All done! ✨ 🍰 ✨
1 file left unchanged.

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:

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,
    )

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:

    """
    Some really really really really really really really really really really really really really really really really long comment
    """

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

  • Black's version: black, 23.12.1 (compiled: yes)
  • OS and Python version: Python (CPython) 3.11.5, Windows 11, WSL2 running Ubuntu 22.04.3 LTS
@marianatuma marianatuma added the T: bug Something isn't working label Jan 26, 2024
@JelleZijlstra
Copy link
Collaborator

Could you give a sample of the code that Black is not formatting correctly?

@marianatuma
Copy link
Author

marianatuma commented Jan 26, 2024

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,
    )
 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:

``` python
    """
    Some really really really really really really really really really really really really really really really really long comment
    """

I'll add this to the original question. (I edited the examples to reflect my current config of line length being 80)

@JelleZijlstra JelleZijlstra added the F: linetoolong Black makes our lines too long label Jan 26, 2024
@JelleZijlstra
Copy link
Collaborator

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.

@marianatuma
Copy link
Author

I'll bring this up with the team, thanks.

@JelleZijlstra JelleZijlstra changed the title Black doesn't break long lines, and reverts manually broken lines Line too long: Long from import Jan 28, 2024
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 T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants