X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/3ddf73337d606442069e5608e62a8367fbacdb40..29e97d1d4a7717f1bd0ca35cacf2f2ce6d815b0c:/black.py diff --git a/black.py b/black.py index dd2e2d1..a03b9aa 100644 --- a/black.py +++ b/black.py @@ -341,8 +341,8 @@ def format_file_in_place( with open(src, "w", encoding=src_buffer.encoding) as f: f.write(dst_contents) elif write_back == write_back.DIFF: - src_name = f"{src.name} (original)" - dst_name = f"{src.name} (formatted)" + src_name = f"{src} (original)" + dst_name = f"{src} (formatted)" diff_contents = diff(src_contents, dst_contents, src_name, dst_name) if lock: lock.acquire() @@ -428,7 +428,6 @@ def format_str(src_contents: str, line_length: int) -> FileContent: GRAMMARS = [ pygram.python_grammar_no_print_statement_no_exec_statement, pygram.python_grammar_no_print_statement, - pygram.python_grammar_no_exec_statement, pygram.python_grammar, ] @@ -1045,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 @@ -1159,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(