Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Commit e5f8251

Browse files
committed
Allow up to two empty lines on module level and single empty lines otherwise
Fixes pytest-dev#74
1 parent 1f445a0 commit e5f8251

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ always emit an extra empty line after ``return``, ``raise``, ``break``,
218218
``continue``, and ``yield``. This is to make changes in control flow
219219
more prominent to readers of your code.
220220

221-
*Black* will allow single empty lines left by the original editors,
222-
except when they're added within parenthesized expressions. Since such
223-
expressions are always reformatted to fit minimal space, this whitespace
224-
is lost.
221+
*Black* will allow single empty lines inside functions, and single and
222+
double empty lines on module level left by the original editors, except
223+
when they're within parenthesized expressions. Since such expressions
224+
are always reformatted to fit minimal space, this whitespace is lost.
225225

226226
It will also insert proper spacing before and after function definitions.
227227
It's one line before and after inner functions and two lines before and
@@ -338,6 +338,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
338338
* fixed 18.3a4 regression: don't crash and burn on empty lines with
339339
trailing whitespace (#80)
340340

341+
* only allow up to two empty lines on module level and only single empty
342+
lines within functions (#74)
343+
341344

342345
### 18.3a4
343346

black.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,13 @@ def maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
754754

755755
def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
756756
max_allowed = 1
757-
if current_line.is_comment and current_line.depth == 0:
757+
if current_line.depth == 0:
758758
max_allowed = 2
759759
if current_line.leaves:
760760
# Consume the first leaf's extra newlines.
761761
first_leaf = current_line.leaves[0]
762762
before = first_leaf.prefix.count('\n')
763-
before = min(before, max(before, max_allowed))
763+
before = min(before, max_allowed)
764764
first_leaf.prefix = ''
765765
else:
766766
before = 0

tests/empty_lines.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ def f():
1212
if t == token.COMMENT: # another trailing comment
1313
return DOUBLESPACE
1414

15+
1516
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
1617

18+
1719
prev = leaf.prev_sibling
1820
if not prev:
1921
prevp = preceding_leaf(p)
2022
if not prevp or prevp.type in OPENING_BRACKETS:
2123

24+
2225
return NO
2326

27+
2428
if prevp.type == token.EQUAL:
2529
if prevp.parent and prevp.parent.type in {
2630
syms.typedargslist,

0 commit comments

Comments
 (0)