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

Commit

Permalink
[pytest-dev#154] Handle comments between decorators properly (pytest-…
Browse files Browse the repository at this point in the history
  • Loading branch information
csurfer authored and ambv committed Apr 24, 2018
1 parent 337a419 commit 29e97d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions black.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
# Don't insert empty lines between decorators.
return 0, 0

if is_decorator and self.previous_line and self.previous_line.is_comment:
# Don't insert empty lines between decorator comments.
return 0, 0

newlines = 2
if current_line.depth:
newlines -= 1
Expand Down
8 changes: 8 additions & 0 deletions tests/comments6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@property
# TODO: X
@property
# TODO: Y
# TODO: Z
@property
def foo():
pass
8 changes: 8 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ def test_check_diff_use_together(self) -> None:
)
self.assertEqual(result.exit_code, 1)

@patch("black.dump_to_file", dump_to_stderr)
def test_comment_in_decorator(self) -> None:
source, expected = read_data("comments6")
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, line_length=ll)


if __name__ == "__main__":
unittest.main()

0 comments on commit 29e97d1

Please sign in to comment.