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

Break long with statements using backslashes if parentheses aren't usable #3484

Closed
tdegeus opened this issue Jan 8, 2023 · 5 comments
Closed
Labels
F: linebreak How should we split up lines? F: linetoolong Black makes our lines too long help wanted Extra attention is needed S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?

Comments

@tdegeus
Copy link

tdegeus commented Jan 8, 2023

Describe the style change

Consider this example

        with g5.ExtendableList(output, "r", np.uint64) as dset_r,\
             g5.ExtendableList(output, "t", np.float64) as dset_t,\
             g5.ExtendableList(output, "dx", np.float64) as dset_dx,\
             g5.ExtendableList(output, "ds", np.int64) as dset_ds:

Examples in the current Black style

        with g5.ExtendableList(output, "r", np.uint64) as dset_r, g5.ExtendableList(
            output, "t", np.float64
        ) as dset_t, g5.ExtendableList(output, "dx", np.float64) as dset_dx, g5.ExtendableList(
            output, "ds", np.int64
        ) as dset_ds:

Desired style

For example:

        with g5.ExtendableList(output, "r", np.uint64) as dset_r,\
             g5.ExtendableList(output, "t", np.float64) as dset_t,\
             g5.ExtendableList(output, "dx", np.float64) as dset_dx,\
             g5.ExtendableList(output, "ds", np.int64) as dset_ds:

Additional context

Using with is crucial as some flushing is needed at the end.

@tdegeus tdegeus added the T: style What do we want Blackened code to look like? label Jan 8, 2023
@tdegeus tdegeus changed the title with foo(...) as file, foo(...) as file2, ... grouped with foo(...) as file Jan 8, 2023
@JelleZijlstra JelleZijlstra added the F: linebreak How should we split up lines? label Jan 8, 2023
@ichard26 ichard26 added the S: accepted The changes in this design / enhancement issue have been accepted and can be implemented label Jan 19, 2023
@ichard26
Copy link
Collaborator

This is documented in the documentation as something we want to do. No one has picked this up though AFAIK (as far as I know).

@JelleZijlstra
Copy link
Collaborator

There is a PR for this, #3489.

@tdegeus
Copy link
Author

tdegeus commented Jan 19, 2023

Amazing !!

@ichard26 ichard26 added help wanted Extra attention is needed F: linetoolong Black makes our lines too long labels Feb 1, 2023
@ichard26
Copy link
Collaborator

ichard26 commented Feb 1, 2023

While #3489 did improve the story for when the target version is 3.9 or higher, Black still poorly formats long with statements when parentheses are not an option. We would like to implement the style documented here (which happens to be the "desired style" in this issue too) but it's unlikely any one on the core team will pick this up anytime soon. External contributions would be appreciated!

@ichard26 ichard26 changed the title grouped with foo(...) as file Break long with statements using backslashes if parentheses aren't usable Feb 1, 2023
@JelleZijlstra
Copy link
Collaborator

Given that the backslash syntax is only necessary in Python 3.8, which will go EOL in a few months, I don't think I'd accept a PR adding support for it at this point. We should consistently use the nicer 3.9+ syntax with parentheses where possible, and leave the current style alone otherwise.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? F: linetoolong Black makes our lines too long help wanted Extra attention is needed S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

4 participants