Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ccd8bb

Browse files
committedApr 22, 2024·
Add support to style function definitions containing newlines before function stubs
1 parent 735733b commit 3ccd8bb

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed
 

‎CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
<!-- Changes to the parser or to version autodetection -->
2828

29+
- Add support to style function definitions containing newlines before function stubs
30+
(#4318)
31+
2932
### Performance
3033

3134
<!-- Changes that improve Black's performance. -->

‎src/black/linegen.py

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ def visit_default(self, node: LN) -> Iterator[Line]:
159159
normalize_numeric_literal(node)
160160
if node.type not in WHITESPACE:
161161
self.current_line.append(node)
162+
if node.type == token.DOT:
163+
node.prefix = node.prefix.lstrip("\n")
162164
yield from super().visit_default(node)
163165

164166
def visit_test(self, node: Node) -> Iterator[Line]:

‎tests/data/cases/stub_empty_line.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class C:
2+
def f(self):
3+
4+
...
5+
# output
6+
class C:
7+
def f(self): ...
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class C:
2+
def f(self):
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
...
13+
# output
14+
class C:
15+
def f(self): ...

0 commit comments

Comments
 (0)
Please sign in to comment.