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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain why black avoids using \ for code organization #392

Closed
zsol opened this issue Jul 2, 2018 · 3 comments 路 Fixed by #1399
Closed

Explain why black avoids using \ for code organization #392

zsol opened this issue Jul 2, 2018 · 3 comments 路 Fixed by #1399
Labels
good first issue Good for newcomers help wanted Extra attention is needed T: documentation Improvements to the docs (e.g. new topic, correction, etc)

Comments

@zsol
Copy link
Collaborator

zsol commented Jul 2, 2018

The README should have a clear, concise explanation for why black avoids using \.

Here's a lengthy reasoning 馃憖

@zsol zsol added help wanted Extra attention is needed good first issue Good for newcomers T: documentation Improvements to the docs (e.g. new topic, correction, etc) labels Jul 2, 2018
@sudheer-g
Copy link

Hey! I've read @ambv 's explanation on this. Is it okay if I give this a shot? Thanks.

@ambv
Copy link
Collaborator

ambv commented Oct 10, 2018

Of course, go for it!

@ambv
Copy link
Collaborator

ambv commented Mar 3, 2020

Wording to use:

Backslashes are one of the two places in the Python grammar that break significant indentation. The other one is multiline strings. You never need backslashes, they are used to force the grammar to accept breaks that would otherwise be parse errors. That makes them confusing to look at and brittle to modify. This is why Black always gets rid of them.

If you're reaching for backslashes, that's a clear signal that you can do better if you slightly refactor your code. I hope some of the examples above show you that there are many ways in which you can do it.

However, there will be one exception: with statements with multiple context managers: #664

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed T: documentation Improvements to the docs (e.g. new topic, correction, etc)
Projects
None yet
3 participants