[#154] Handle comments between decorators properly (#166)

This commit is contained in:
Vishwas B Sharma 2018-04-24 09:38:12 -07:00 committed by Łukasz Langa
parent 337a4199f9
commit 29e97d1d4a
3 changed files with 20 additions and 0 deletions

View File

@ -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

8
tests/comments6.py Normal file
View File

@ -0,0 +1,8 @@
@property
# TODO: X
@property
# TODO: Y
# TODO: Z
@property
def foo():
pass

View File

@ -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()