Commit 29e97d1d authored by Vishwas B Sharma's avatar Vishwas B Sharma Committed by Łukasz Langa
Browse files

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

parent 337a4199
Loading
Loading
Loading
Loading
+4 −0
Changes for black.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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

tests/comments6.py

0 → 100644
+8 −0
Changes for tests/comments6.py: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@property
# TODO: X
@property
# TODO: Y
# TODO: Z
@property
def foo():
    pass
+8 −0
Changes for tests/test_black.py: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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()