Skip to content

Commit

Permalink
Keep requiring two empty lines between module-level docstring and fir…
Browse files Browse the repository at this point in the history
…st function or class definition.

Fixes psf#4027.
  • Loading branch information
yilei committed Nov 6, 2023
1 parent 9e3daa1 commit 61d8400
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
indented less (#3964)
- Multiline list and dict unpacking as the sole argument to a function is now also
indented less (#3992)
- Keep requiring two empty lines between module-level docstring and first function or
class definition. (#4028)

### Configuration

Expand Down
1 change: 1 addition & 0 deletions src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ def maybe_empty_lines(self, current_line: Line) -> LinesBlock:
and self.previous_block.previous_block is None
and len(self.previous_block.original_line.leaves) == 1
and self.previous_block.original_line.is_triple_quoted_string
and not (current_line.is_class or current_line.is_def)
):
before = 1

Expand Down
11 changes: 11 additions & 0 deletions tests/data/cases/module_docstring_followed_by_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# flags: --preview
"""Two blank lines between module docstring and a class."""
class MyClass:
pass

# output
"""Two blank lines between module docstring and a class."""


class MyClass:
pass
11 changes: 11 additions & 0 deletions tests/data/cases/module_docstring_followed_by_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# flags: --preview
"""Two blank lines between module docstring and a function def."""
def function():
pass

# output
"""Two blank lines between module docstring and a function def."""


def function():
pass

0 comments on commit 61d8400

Please sign in to comment.