Loading black.py +29 −21 Changes for black.py: 29 added lines, 21 removed lines. Original line number Diff line number Diff line Loading @@ -1390,10 +1390,31 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]: before = 0 if depth else 1 else: before = 1 if depth else 2 is_decorator = current_line.is_decorator if is_decorator or current_line.is_def or current_line.is_class: if not is_decorator: self.previous_defs.append(depth) if current_line.is_decorator or current_line.is_def or current_line.is_class: return self._maybe_empty_lines_for_class_or_def(current_line, before) if ( self.previous_line and self.previous_line.is_import and not current_line.is_import and depth == self.previous_line.depth ): return (before or 1), 0 if ( self.previous_line and self.previous_line.is_class and current_line.is_triple_quoted_string ): return before, 1 return before, 0 def _maybe_empty_lines_for_class_or_def( self, current_line: Line, before: int ) -> Tuple[int, int]: if not current_line.is_decorator: self.previous_defs.append(current_line.depth) if self.previous_line is None: # Don't insert empty lines before the first line in the file. return 0, 0 Loading @@ -1418,9 +1439,13 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]: newlines = 1 elif current_line.is_class or self.previous_line.is_class: if current_line.is_stub_class and self.previous_line.is_stub_class: # No blank line between classes with an emty body newlines = 0 else: newlines = 1 elif current_line.is_def and not self.previous_line.is_def: # Blank line between a block of functions and a block of non-functions newlines = 1 else: newlines = 0 else: Loading @@ -1429,23 +1454,6 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]: newlines -= 1 return newlines, 0 if ( self.previous_line and self.previous_line.is_import and not current_line.is_import and depth == self.previous_line.depth ): return (before or 1), 0 if ( self.previous_line and self.previous_line.is_class and current_line.is_triple_quoted_string ): return before, 1 return before, 0 @dataclass class LineGenerator(Visitor[Line]): Loading tests/data/stub.pyi +8 −0 Changes for tests/data/stub.pyi: 8 added lines, 0 removed lines. Original line number Diff line number Diff line X: int def f(): ... class C: ... Loading @@ -16,6 +20,10 @@ def g(): def h(): ... # output X: int def f(): ... class C: ... class B: ... Loading Loading
black.py +29 −21 Changes for black.py: 29 added lines, 21 removed lines. Original line number Diff line number Diff line Loading @@ -1390,10 +1390,31 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]: before = 0 if depth else 1 else: before = 1 if depth else 2 is_decorator = current_line.is_decorator if is_decorator or current_line.is_def or current_line.is_class: if not is_decorator: self.previous_defs.append(depth) if current_line.is_decorator or current_line.is_def or current_line.is_class: return self._maybe_empty_lines_for_class_or_def(current_line, before) if ( self.previous_line and self.previous_line.is_import and not current_line.is_import and depth == self.previous_line.depth ): return (before or 1), 0 if ( self.previous_line and self.previous_line.is_class and current_line.is_triple_quoted_string ): return before, 1 return before, 0 def _maybe_empty_lines_for_class_or_def( self, current_line: Line, before: int ) -> Tuple[int, int]: if not current_line.is_decorator: self.previous_defs.append(current_line.depth) if self.previous_line is None: # Don't insert empty lines before the first line in the file. return 0, 0 Loading @@ -1418,9 +1439,13 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]: newlines = 1 elif current_line.is_class or self.previous_line.is_class: if current_line.is_stub_class and self.previous_line.is_stub_class: # No blank line between classes with an emty body newlines = 0 else: newlines = 1 elif current_line.is_def and not self.previous_line.is_def: # Blank line between a block of functions and a block of non-functions newlines = 1 else: newlines = 0 else: Loading @@ -1429,23 +1454,6 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]: newlines -= 1 return newlines, 0 if ( self.previous_line and self.previous_line.is_import and not current_line.is_import and depth == self.previous_line.depth ): return (before or 1), 0 if ( self.previous_line and self.previous_line.is_class and current_line.is_triple_quoted_string ): return before, 1 return before, 0 @dataclass class LineGenerator(Visitor[Line]): Loading
tests/data/stub.pyi +8 −0 Changes for tests/data/stub.pyi: 8 added lines, 0 removed lines. Original line number Diff line number Diff line X: int def f(): ... class C: ... Loading @@ -16,6 +20,10 @@ def g(): def h(): ... # output X: int def f(): ... class C: ... class B: ... Loading