Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add test cases (in the same file) where there are comments in various places around the ..., e.g. on a line by itself or right after :.

...
# 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): ...