Skip to content

Commit

Permalink
Merge d611810 into 85eeea1
Browse files Browse the repository at this point in the history
  • Loading branch information
sudheer-g committed Oct 19, 2018
2 parents 85eeea1 + d611810 commit 7fe6ae8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,54 @@ between two distinct sections of the code that otherwise share the same
indentation level (like the arguments list and the docstring in the
example above).

*Black* prefers parentheses over backslashes, and will remove backslashes
if found.
```py3
# in:

if some_short_rule1 \
and some_short_rule2:
...

# out:

if some_short_rule1 and some_short_rule2:
...


# in:

if some_long_rule1 \
and some_long_rule2:
...

# out:

if (
some_long_rule1
and some_long_rule2
):
...

```

This is because Python has significant indentation for blocks
ending with a colon. However, that is not the case with backslashes.
```py3
if True:
print("significant indent")

if some_long_rule_rule1 \
and some_long_rule2:
print("Unclear indentation")

```
The problem with backslashes is that there is no closing token for *Black*
to let the user know that a block has ended. Other formatters and PEP 8 work
around this problem by creating extra indentation, but *Black*
considers this bad as it can cause a cascading effect on formatting if the line
is too long and won't fit.

If a data structure literal (tuple, list, set, dict) or a line of "from"
imports cannot fit in the allotted length, it's always split into one
element per line. This minimizes diffs as well as enables readers of
Expand Down

0 comments on commit 7fe6ae8

Please sign in to comment.