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

Formatting of long expressions in arguments #3510

Open
oskarkk opened this issue Jan 21, 2023 · 0 comments
Open

Formatting of long expressions in arguments #3510

oskarkk opened this issue Jan 21, 2023 · 0 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@oskarkk
Copy link

oskarkk commented Jan 21, 2023

Describe the style change

#3440 (closing #620 and #808) improved handling of long expressions in dict values by putting them in parentheses, but the same values in function arguments aren't always handled nicely.

Examples in the current Black style

dict(
    key_key_key_key=a_long_long_long_long_long
    * b_long_long_long_long_long
    / 100.0
)

dict(
    key_key_key_key_key_key_key_key_key=lambda: some_very_long_function_name(
        x, y, z
    )
)

Desired style

dict(
    key_key_key_key=(
        a_long_long_long_long_long * b_long_long_long_long_long / 100.0
    )
)

dict(
    key_key_key_key_key_key_key_key_key=(
        lambda: some_very_long_function_name(x, y, z)
    )
)

Additional context

The above problem surprisingly isn't present when the expression is the ternary operator. I found this related issue: #2248, and I think it could be closed now, as on the --preview on main it's fixed.

Here's a comparison of some structures where formatting is good and not good:

https://black.vercel.app/?version=main&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4AVtAZFdAD2IimZxl1N_Wg0-DjgFSwwpr4QAHGnZVCigXiEsaw3kDKWOCEa4OyVpau2mCKO2huSgEtYJFakCvJdOz0Tnz9A9VXZaY6yvVt0g0T7eVV1sdafqJHPQjFCF87XgeS5o61J0hfwUrJyv9vemJ3drIV67OMA4NPtoBxDB0jAnP0w3_FCw4CwHZNzHatn3Mmo8JDZbQgL9tZuHGhbY93lVPrMOOj7V13lJpYG7iN4EAeOxV-wIMLcnBSj9dt2P1447cRZOFBAPbIbLCz6KCdzbNRgUw7Z2AoNrHepi73I-BQJ-tVCrypINXFeYTLtWI5ijTFPZ_c48_7tnfGJvb9lSt20aVWHGlcDJzbeHWZA5x90aMTtBD_YqD4xSuSyF2kcLxHFGTemWtI7jxvkqSbsB1L1TVuEqG1ERUBH7wYVedEYUorPtewAk13xN8SdhklZ3xTKO_WsKJ2NSK4bvFkLnxJuMSyIlc0tGdWdyFUdJub9EJwuKoneabBy__ez6gsL3D1DbXrAxE-ETk4_7yaQi0S4AAAAAAK98cuj9XVqQAAGtA-4KAADgH0AascRn-wIAAAAABFla

Without preview enabled, cases A-J excluding E are ugly, with preview enabled only C, D, I and J are ugly (and these are the examples presented above).

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

1 participant