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

Multiline f-strings aren't formatted correctly #2747

Closed
Alphasite opened this issue Jan 4, 2022 · 2 comments
Closed

Multiline f-strings aren't formatted correctly #2747

Alphasite opened this issue Jan 4, 2022 · 2 comments
Labels
F: strings Related to our handling of strings R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@Alphasite
Copy link

Describe the bug

When you have multiple f-strings (I suspect without a + between them) then when it reformats them it
will just remove the new lines without merging the strings into a single compound string, e.g. f"{1}" f" {2}"
rather than f"{1} {2}"

To Reproduce

c.run(
    f"docker login {self.hostname} "
    f"--username {self.username} "
    f"--password {self.password}",
)

For example, take this code:

this = "code"

And run it with these arguments:

$ poetry run black src

The resulting error is:

         c.run(
-            f"docker login {self.hostname} "
-            f"--username {self.username} "
-            f"--password {self.password}",
+            f"docker login {self.hostname} " f"--username {self.username} " f"--password {self.password}",
         )

Expected behavior

         c.run(
-            f"docker login {self.hostname} "
-            f"--username {self.username} "
-            f"--password {self.password}",
+            f"docker login {self.hostname} --username {self.username} --password {self.password}",
         )

Environment

  • Black's version: black, 21.12b0 (compiled: no)
  • OS and Python version: Mac/Python 3.9

Additional context

@Alphasite Alphasite added the T: bug Something isn't working label Jan 4, 2022
@felix-hilden felix-hilden added F: strings Related to our handling of strings R: duplicate This issue or pull request already exists labels Jan 4, 2022
@felix-hilden
Copy link
Collaborator

felix-hilden commented Jan 4, 2022

I believe this is fixed by using black --experimental-string-processing, which will soon become standard functionality, tracked in #2188.

$ black -c "f\"a\" f\"b\""
f"a" f"b"

$ black -c "f\"a\" f\"b\"" --experimental-string-processing
f"ab"

@Alphasite
Copy link
Author

Oh thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: strings Related to our handling of strings R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants