Inconsistencies with auto-format

Bug description:
when I auto-format code, it will make some print statements like this

print("Text")

and some like this

print(
           "Text"
          )

Expected vs Current Behavior:
I would expect that it makes all either one or the other. It’s very annoying to have such large inconsistencies.

Screenshot(s)/Screen Recording:

Replit Profile: https://replit.com/@DigitalKandra

Hello,
this is intended behavior because it is trying to keep line length under a certain limit.

2 Likes

Can I turn it off? It’s quite pointless, the longer lines work fine.

That confuses me, it’s not like it makes the line any shorter.

I do not know of any way to configure the formatter. There are ways to make the lines shorter, though, because it is generally bad to have massively long lines.

This is how the formatter tries to make the line shorter (here the line length limit is low)

#abcdefghijklmnopq
print("123456789")

#abcdefghijklmn
print(
    "123456789"
)

Unfortunately, this line shortening technique does not work well in this case, where you have one long string. It only shortens it by a few characters here.

I would recommend breaking up your long strings using implicit concatenation.

print(
    "this "
    "is one "
    "string"
)
print("another "
      "example...")

Auto-format is not really inconsistent, it is just being ineffective here. I don’t use auto-format myself because I write code formatted well (this gives you complete control!). If you must use auto-format, I’d either ignore this or fix the long lines.

3 Likes

key reason to (configure and) use black

3 Likes