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

String processing produces code exceeding length limit #2294

Closed
Jackenmen opened this issue May 31, 2021 · 4 comments · Fixed by #2312
Closed

String processing produces code exceeding length limit #2294

Jackenmen opened this issue May 31, 2021 · 4 comments · Fixed by #2312
Labels
F: linetoolong Black makes our lines too long F: strings Related to our handling of strings T: bug Something isn't working

Comments

@Jackenmen
Copy link
Contributor

Jackenmen commented May 31, 2021

Describe the bug

String processing produces code exceeding the length limit when it was already formatted properly before.

To Reproduce

For example:

  1. Take this file:
class X:
    async def foo(self):
        msg = ""
        for candidate in CANDIDATES:
            msg += (
                "**{candidate.object_type} {candidate.rev}**"
                " - {candidate.description}\n"
            )
  1. Run Black on it with these arguments --experimental-string-processing
  2. See the reformatted code that exceeds line length limit:
class X:
    async def foo(self):
        msg = ""
        for candidate in CANDIDATES:
            msg += "**{candidate.object_type} {candidate.rev}** - {candidate.description}\n"

Expected behavior

I expected the code to remain unchanged.

Environment (please complete the following information):

  • Version: main (cf75673 at the time of testing)
  • OS and Python version: Windows 10/Python 3.8.9

Does this bug also happen on main?

Yes.

Additional context

I was unable to find another issue that would seem to be the same as this though it's possible I missed something. Just to be sure it's not about the same thing #2284 is, I also tried out the changes from #2292 (since they apparently fix some edge cases that weren't fixed by #2286.
Also, the original code actually contained f-string but to rule out that it has anything to do with #2293, I changed it to use regular strings which as you can see from the issue description didn't change the end result.

@Jackenmen
Copy link
Contributor Author

Probably what's also important here is that Black doesn't try to split this string despite it being too long:

class X:
    async def foo(self):
        msg = ""
        for candidate in CANDIDATES:
            msg += "**{candidate.object_type} {candidate.rev}** - {candidate.description}\n"

After a second look, it appears that usage of += is the key issue here - it works fine when replacing it with =

@JelleZijlstra JelleZijlstra added the F: strings Related to our handling of strings label Jun 1, 2021
@JelleZijlstra
Copy link
Collaborator

Does #2292 fix this?

@JelleZijlstra JelleZijlstra added the F: linetoolong Black makes our lines too long label Jun 1, 2021
@JelleZijlstra
Copy link
Collaborator

Never mind, you already discussed it.

@bbugyi200
Copy link
Contributor

This issue should be fixed by the following PR: #2312

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 F: strings Related to our handling of strings T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants