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

Combine f-strings which would be placed on the same line #4389

Open
pushfoo opened this issue Jun 26, 2024 · 4 comments
Open

Combine f-strings which would be placed on the same line #4389

pushfoo opened this issue Jun 26, 2024 · 4 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@pushfoo
Copy link

pushfoo commented Jun 26, 2024

Describe the style change

Combine short f-string segements which would be placed on the same line

Examples in the current Black style

  1. Input: use a multi-part f-string shorter than line length
    sep= " "
    FSTRING = (
        f"many"
        f"{sep}"
        f"tiny"
        f"{sep}"
        f"fstrings"
    )
  2. Run it locally or via this vercel example
  3. The output wastes horizontal space: it puts them on one line, but not joined together
    sep= " "
    FSTRING = f"many" f"{sep}" f"tiny" f"{sep}" f"fstrings"

Desired style

sep = " "
FSTRING = f"many{sep}tiny{sep}fstrings"

Additional context
Originally found while reviewing a PR for Python Arcade, a game framework and educational tool.

@pushfoo pushfoo added the T: style What do we want Blackened code to look like? label Jun 26, 2024
@pushfoo pushfoo changed the title Join f-string components which would be placed on the same line Combine f-strings which would be placed on the same line Jun 26, 2024
@nottarun7
Copy link

Which file is the current function in or is there a need to create a new file?

@kastkeepitjumpinlikekangaroos

hey! I've opened a PR here #4480 implementing a change for this issue FYI! Currently awaiting feedback (not sure what the standard protocol for issues like this which haven't been officially accepted yet but this seems to be a net improvement to the formatting IMO)

@cobaltt7
Copy link
Contributor

This feature already exists in the --unstable style (string_processing feature)

See #4208

@kastkeepitjumpinlikekangaroos

ah thanks @cobaltt7 - will close the PR then!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

4 participants