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

Multi-lines with block should be allowed to use backslashes to wrap their lines #1378

Closed
seirl opened this issue May 4, 2020 · 2 comments
Closed
Labels
T: style What do we want Blackened code to look like?

Comments

@seirl
Copy link

seirl commented May 4, 2020

Describe the style change Multi-lines with block should be allowed to use backslashes to wrap their lines.

Examples in the current Black style

        with ZSTFile(nodes_file, "w") as nodes_writer, ZSTFile(
            edges_file, "w"
        ) as edges_writer:

Desired style

        with \
                ZSTFile(nodes_file, 'w') as nodes_writer, \
                ZSTFile(edges_file, 'w') as edges_writer:

Additional context Add any other context about the problem here.

This is a well-known place where backslashes are a valid form of line continuation in Python. It makes the separation between lines a lot clearer.

I know this could be rewritten using ExitStack, but I don't think this is a good reason for Black to generate unreadable lines by default when people are not using ExitStack.

@seirl seirl added the T: style What do we want Blackened code to look like? label May 4, 2020
@intgr
Copy link

intgr commented May 5, 2020

Unfortunately there isn't a nicer way to format with blocks.

I really wish Python allowed optional parentheses in the with syntax, like this

        with (
            ZSTFile(nodes_file, 'w') as nodes_writer,
            ZSTFile(edges_file, 'w') as edges_writer,
        ):

@seirl
Copy link
Author

seirl commented May 5, 2020

Duplicate of #664 apparently.

@seirl seirl closed this as completed May 5, 2020
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

2 participants