X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/82198030eef6f99ad47470d82c34d9a6e1a4e6df..29e97d1d4a7717f1bd0ca35cacf2f2ce6d815b0c:/black.py?ds=inline diff --git a/black.py b/black.py index da645a1..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 @@ -1158,7 +1162,16 @@ class LineGenerator(Visitor[Line]): def visit_DEDENT(self, node: Node) -> Iterator[Line]: """Decrease indentation level, maybe yield a line.""" - # DEDENT has no value. Additionally, in blib2to3 it never holds comments. + # The current line might still wait for trailing comments. At DEDENT time + # there won't be any (they would be prefixes on the preceding NEWLINE). + # Emit the line then. + yield from self.line() + + # While DEDENT has no value, its prefix may contain standalone comments + # that belong to the current indentation level. Get 'em. + yield from self.visit_default(node) + + # Finally, emit the dedent. yield from self.line(-1) def visit_stmt(