Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview: Keep requiring two empty lines between module-level docstring and first function or class definition. #4028

Merged
merged 1 commit into from Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
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
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
@@ -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
@@ -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