#1467·black

[string_preprocessing] When splitting lines, `\n` is ignored

Author: JackenmenCreated May 31, 2020Updated Sep 13, 2026
LabelsT: styleF: stringsC: preview style

Describe the style change [string_preprocessing] Black should respect new lines (\n) in strings.

Input:

python
message = (
    "1. Go to Google Developers Console and log in with your favourite Google account.\n"
    "(https://console.developers.google.com/)\n"
    "2. You should be prompted to create a new project (name does not matter).\n"
    "3. Click on Enable APIs and Services at the top.\n"
    "4. In the list of APIs choose or search for YouTube Data API v3 and "
    "click on it. Choose Enable.\n"
    "5. Click on Credentials on the left navigation bar.\n"
    "6. Click on Create Credential at the top.\n"
    '7. At the top click the link for "API key".\n'
    "8. No application restrictions are needed. Click Create at the bottom.\n"
    "9. You now have a key to add to `[p]set api youtube api_key <your_api_key_here>`"
)

Examples in the current Black style:

python
message = (
    "1. Go to Google Developers Console and log in with your favourite Google"
    " account.\n(https://console.developers.google.com/)\n2. You should be prompted to"
    " create a new project (name does not matter).\n3. Click on Enable APIs and"
    " Services at the top.\n4. In the list of APIs choose or search for YouTube Data"
    " API v3 and click on it. Choose Enable.\n5. Click on Credentials on the left"
    " navigation bar.\n6. Click on Create Credential at the top.\n7. At the top click"
    ' the link for "API key".\n8. No application restrictions are needed. Click Create'
    " at the bottom.\n9. You now have a key to add to `[p]set api youtube api_key"
    " <your_api_key_here>`"
)

Desired style: (place in which I split the 1. is random, I just mean that Black should respect \n)

python
message = (
    "1. Go to Google Developers Console and log in with your favourite"
    " Google account.\n"
    "(https://console.developers.google.com/)\n"
    "2. You should be prompted to create a new project (name does not matter).\n"
    "3. Click on Enable APIs and Services at the top.\n"
    "4. In the list of APIs choose or search for YouTube Data API v3 and "
    "click on it. Choose Enable.\n"
    "5. Click on Credentials on the left navigation bar.\n"
    "6. Click on Create Credential at the top.\n"
    '7. At the top click the link for "API key".\n'
    "8. No application restrictions are needed. Click Create at the bottom.\n"
    "9. You now have a key to add to `[p]set api youtube api_key <your_api_key_here>`"
)

Additional context: None

I'm sorry for the amount of issues but I tried to run Black's master on Cog-Creators/Red-DiscordBot's code base which resulted in quite a few of errors and also some undesired (by me) changes which I wanted to at least report even if they're not gonna be changed.