Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2fd9d8b

Browse files
Remove blank lines before class docstring (psf#3692)
1 parent db3668a commit 2fd9d8b

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Implicitly concatenated strings used as function args are no longer wrapped inside
1818
parentheses (#3640)
19+
- Remove blank lines between a class definition and its docstring (#3692)
1920

2021
### Configuration
2122

src/black/lines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
634634
and self.previous_line.is_class
635635
and current_line.is_triple_quoted_string
636636
):
637+
if Preview.no_blank_line_before_class_docstring in current_line.mode:
638+
return 0, 1
637639
return before, 1
638640

639641
if self.previous_line and self.previous_line.opens_block:

src/black/mode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class Preview(Enum):
158158
hex_codes_in_unicode_sequences = auto()
159159
improved_async_statements_handling = auto()
160160
multiline_string_handling = auto()
161+
no_blank_line_before_class_docstring = auto()
161162
prefer_splitting_right_hand_side_of_assignments = auto()
162163
# NOTE: string_processing requires wrap_long_dict_values_in_parens
163164
# for https://github.com/psf/black/issues/3117 to be fixed.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
def line_before_docstring():
2+
3+
"""Please move me up"""
4+
5+
6+
class LineBeforeDocstring:
7+
8+
"""Please move me up"""
9+
10+
11+
class EvenIfThereIsAMethodAfter:
12+
13+
"""I'm the docstring"""
14+
def method(self):
15+
pass
16+
17+
18+
class TwoLinesBeforeDocstring:
19+
20+
21+
"""I want to be treated the same as if I were closer"""
22+
23+
24+
class MultilineDocstringsAsWell:
25+
26+
"""I'm so far
27+
28+
and on so many lines...
29+
"""
30+
31+
32+
# output
33+
34+
35+
def line_before_docstring():
36+
"""Please move me up"""
37+
38+
39+
class LineBeforeDocstring:
40+
"""Please move me up"""
41+
42+
43+
class EvenIfThereIsAMethodAfter:
44+
"""I'm the docstring"""
45+
46+
def method(self):
47+
pass
48+
49+
50+
class TwoLinesBeforeDocstring:
51+
"""I want to be treated the same as if I were closer"""
52+
53+
54+
class MultilineDocstringsAsWell:
55+
"""I'm so far
56+
57+
and on so many lines...
58+
"""

0 commit comments

Comments
 (0)