Skip to content

Commit

Permalink
Fix an issue where empty lines were added between comments inside dec…
Browse files Browse the repository at this point in the history
…orators.
  • Loading branch information
yilei committed Oct 7, 2022
1 parent 3318fd5 commit 524cc6b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ def maybe_empty_lines(self, current_line: Line) -> LinesBlock:
if current_line.is_comment:
if self.previous_line is None or (
not self.previous_line.is_decorator
# `or before` means this comment already has an empty line before
and (not self.previous_line.is_comment or before)
and (self.semantic_leading_comment is None or before)
):
self.semantic_leading_comment = block
Expand Down
2 changes: 2 additions & 0 deletions tests/data/preview/comments9.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MyClassAfterAnotherClassWithDocstring:
# leading 1
@deco1
# leading 2
# leading 2 extra
@deco2(with_args=True)
# leading 3
@deco3
Expand Down Expand Up @@ -158,6 +159,7 @@ class MyClassAfterAnotherClassWithDocstring:
# leading 1
@deco1
# leading 2
# leading 2 extra
@deco2(with_args=True)
# leading 3
@deco3
Expand Down

0 comments on commit 524cc6b

Please sign in to comment.