Skip to content

Commit

Permalink
Add support to style function definitions containing newlines before …
Browse files Browse the repository at this point in the history
…function stubs
  • Loading branch information
peterkra25 committed Apr 22, 2024
1 parent 735733b commit 3ccd8bb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

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

- Add support to style function definitions containing newlines before function stubs
(#4318)

### Performance

<!-- Changes that improve Black's performance. -->
Expand Down
2 changes: 2 additions & 0 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def visit_default(self, node: LN) -> Iterator[Line]:
normalize_numeric_literal(node)
if node.type not in WHITESPACE:
self.current_line.append(node)
if node.type == token.DOT:
node.prefix = node.prefix.lstrip("\n")
yield from super().visit_default(node)

def visit_test(self, node: Node) -> Iterator[Line]:
Expand Down
7 changes: 7 additions & 0 deletions tests/data/cases/stub_empty_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class C:
def f(self):

...
# output
class C:
def f(self): ...
15 changes: 15 additions & 0 deletions tests/data/cases/stub_many_empty_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class C:
def f(self):









...
# output
class C:
def f(self): ...

0 comments on commit 3ccd8bb

Please sign in to comment.