Skip to content

Multiline f-strings aren't formatted correctly #2747

@Alphasite

Description

@Alphasite

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: stringsRelated to our handling of stringsR: duplicateThis issue or pull request already existsT: bugSomething isn't working
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions