Skip to content

Commit b7717c3

Browse files
DanielNoordjpy-gitJelleZijlstra
authored
Standardise newlines after module-level docstrings (#3932)
Co-authored-by: jpy-git <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 7aa37ea commit b7717c3

16 files changed

+132
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Long type hints are now wrapped in parentheses and properly indented when split across
2020
multiple lines (#3899)
2121
- Magic trailing commas are now respected in return types. (#3916)
22+
- Require one empty line after module-level docstrings. (#3932)
2223

2324
### Configuration
2425

scripts/make_width_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
pip install -U wcwidth
1616
1717
"""
18+
1819
import sys
1920
from os.path import basename, dirname, join
2021
from typing import Iterable, Tuple

src/black/cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Caching of formatted files with feature-based invalidation."""
2+
23
import hashlib
34
import os
45
import pickle

src/black/linegen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Generating lines of code.
33
"""
4+
45
import sys
56
from dataclasses import replace
67
from enum import Enum, auto

src/black/lines.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ def maybe_empty_lines(self, current_line: Line) -> LinesBlock:
550550
if self.previous_line is None
551551
else before - previous_after
552552
)
553+
if (
554+
Preview.module_docstring_newlines in current_line.mode
555+
and self.previous_block
556+
and self.previous_block.previous_block is None
557+
and len(self.previous_block.original_line.leaves) == 1
558+
and self.previous_block.original_line.is_triple_quoted_string
559+
):
560+
before = 1
561+
553562
block = LinesBlock(
554563
mode=self.mode,
555564
previous_block=self.previous_block,

src/black/mode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class Preview(Enum):
187187
wrap_multiple_context_managers_in_parens = auto()
188188
dummy_implementations = auto()
189189
walrus_subscript = auto()
190+
module_docstring_newlines = auto()
190191

191192

192193
class Deprecated(UserWarning):

src/black/numerics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Formatting numeric literals.
33
"""
4+
45
from blib2to3.pytree import Leaf
56

67

src/black/parsing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Parse Python code and perform AST validation.
33
"""
4+
45
import ast
56
import sys
67
from typing import Iterable, Iterator, List, Set, Tuple

src/black/report.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Summarize Black runs to users.
33
"""
4+
45
from dataclasses import dataclass
56
from enum import Enum
67
from pathlib import Path

src/black/rusty.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
See https://doc.rust-lang.org/book/ch09-00-error-handling.html.
44
"""
5+
56
from typing import Generic, TypeVar, Union
67

78
T = TypeVar("T")

0 commit comments

Comments
 (0)