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

String processing doesn't respect existing code formatting for f-strings #2293

Closed
Jackenmen opened this issue May 31, 2021 · 4 comments · Fixed by #2311
Closed

String processing doesn't respect existing code formatting for f-strings #2293

Jackenmen opened this issue May 31, 2021 · 4 comments · Fixed by #2311

Comments

@Jackenmen
Copy link
Contributor

Jackenmen commented May 31, 2021

Describe the bug

There is some issue with how Black splits the string if at least one of them is an f-string.

To Reproduce

For example:

  1. Take this file:
message = (
    f"1. Go to Google Developers Console and log in with your Google account."
    "(https://console.developers.google.com/)"
    "2. You should be prompted to create a new project (name does not matter)."
    "3. Click on Enable APIs and Services at the top."
    "4. In the list of APIs choose or search for YouTube Data API v3 and "
    "click on it. Choose Enable."
    "5. Click on Credentials on the left navigation bar."
    "6. Click on Create Credential at the top."
    '7. At the top click the link for "API key".'
    "8. No application restrictions are needed. Click Create at the bottom."
    "9. You now have a key to add to `{prefix}set api youtube api_key`"
)
  1. Run Black on it with --experimental-string-processing flag
  2. See rather bad formatting even though the original respected line length:
message = (
    f"1. Go to Google Developers Console and log in with your Google account."
    f"(https://console.developers.google.com/"
    f")2. You should be prompted to create a new project (name does not matter"
    f").3. Click on Enable APIs and Services at the t"
    f"op.4. In the list of APIs choose or search for YouTube Data API v3 "
    f"and click on it. Choose En"
    f"able.5. Click on Credentials on the left navigatio"
    f"n bar.6. Click on Create Credential at t"
    f'he top.7. At the top click the link for "A'
    f'PI key".8. No application restrictions are needed. Click Create at th'
    f"e bottom.9. You now have a key to add to `{{prefix}}set api youtube api_key`"
)

I'm also not sure why it splits in the middle of the word?

Expected behavior

No

Environment (please complete the following information):

  • Version: main (cf75673 at the time of testing)
  • OS and Python version: Windows 10/Python 3.8.9

Does this bug also happen on main?

Yes

Additional context

N/A

@vaneseltine
Copy link
Contributor

I'm only seeing this with --experimental-string-processing

@Jackenmen
Copy link
Contributor Author

Aaaaand, of course, I forgot to mention that in the description, sorry. I updated the issue description appropriately.

@bbugyi200
Copy link
Contributor

bbugyi200 commented Jun 5, 2021

I'm looking into this. Note that this only occurs when you prefix one or more (but not all) of the substrings with a redundant f (i.e. one of the substrings is an f-string containing no f-expression) and none of the other substrings are valid f-strings (i.e. f-strings that actually contain f-expressions).

@bbugyi200
Copy link
Contributor

This issue should be fixed by the following PR: #2311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants