From: Vishwas B Sharma Date: Tue, 24 Apr 2018 16:38:12 +0000 (-0700) Subject: [#154] Handle comments between decorators properly (#166) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/29e97d1d4a7717f1bd0ca35cacf2f2ce6d815b0c?ds=sidebyside [#154] Handle comments between decorators properly (#166) --- diff --git a/black.py b/black.py index 15a7547..a03b9aa 100644 --- a/black.py +++ b/black.py @@ -1044,6 +1044,10 @@ class EmptyLineTracker: # 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 diff --git a/tests/comments6.py b/tests/comments6.py new file mode 100644 index 0000000..0565015 --- /dev/null +++ b/tests/comments6.py @@ -0,0 +1,8 @@ +@property +# TODO: X +@property +# TODO: Y +# TODO: Z +@property +def foo(): + pass diff --git a/tests/test_black.py b/tests/test_black.py index dd3beed..9c029df 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -626,6 +626,14 @@ class BlackTestCase(unittest.TestCase): ) 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()