autopep8 icon indicating copy to clipboard operation
autopep8 copied to clipboard

Formatting text with variables using f"" lead to not nice break

Open Hadatko opened this issue 1 year ago • 3 comments


Python Code


print(f"{dasdsadasdsadassdsadasdasddasddasd}{dasdsadasdsadasdasddasd}{dasdsadasdsadasdasddasd}")

This lead to

print(f"{dasdsadasdsadassdsadasdasddasddasd}{
dasdsadasdsadasdasddasd}{dasdsadasdsadasdasddasd}")

Better would be

print(f"{dasdsadasdsadassdsadasdasddasddasd}\
{dasdsadasdsadasdasddasd}{dasdsadasdsadasdasddasd}")

or format it as without "f" (like basic string without variables)

Command Line and Configuration

.pep8, setup.cfg, ...

[pep8]

VSCode default

Command Line

$ autopep8 

VSCode default

Your Environment

  • Python version:
  • autopep8 version:
  • Platform: windows, linux, macOSX, and other OS...

Hadatko avatar Aug 09 '24 16:08 Hadatko

This produces errors like

SyntaxError: unterminated string literal (detected at line 60)

Your example could also be broken into multiple lines like

print(f"{dasdsadasdsadassdsadasdasddasddasd}"
      f"{dasdsadasdsadasdasddasd}"
      f"{dasdsadasdsadasdasddasd}")

endolith avatar Sep 04 '24 01:09 endolith

I have also found this issue. Breaking a formatted string like this also causes issue in the output.

aconchillo avatar Sep 19 '24 08:09 aconchillo

Same issue with python 3.12.3, autopep8==2.3.1

cjcdev avatar Sep 28 '24 18:09 cjcdev