Skip to content

Commit

Permalink
Treat stub blank lines in "if" as if top level
Browse files Browse the repository at this point in the history
Resolves psf#2784
  • Loading branch information
hauntsaninja committed Jan 28, 2022
1 parent e150676 commit a49f3c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,8 @@ def _maybe_empty_lines_for_class_or_def(
return 0, 0

if self.is_pyi:
if self.previous_line.depth > current_line.depth:
newlines = 0 if current_line.depth else 1
elif current_line.is_class or self.previous_line.is_class:
if current_line.depth:
if current_line.is_class:
if self.previous_line.depth < current_line.depth:
newlines = 0
elif current_line.is_stub_class and self.previous_line.is_stub_class:
# No blank line between classes with an empty body
Expand All @@ -551,6 +549,8 @@ def _maybe_empty_lines_for_class_or_def(
# Blank line between a block of functions (maybe with preceding
# decorators) and a block of non-functions
newlines = 1
elif self.previous_line.depth > current_line.depth:
newlines = 0 if current_line.depth else 1
else:
newlines = 0
else:
Expand Down
19 changes: 19 additions & 0 deletions tests/data/stub.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def g():

def h(): ...

if sys.version_info >= (3, 8):
class E:
def f(self): ...
class F:

def f(self): ...
class G: ...
class H: ...


# output
X: int
Expand All @@ -56,3 +65,13 @@ class A:

def g(): ...
def h(): ...

if sys.version_info >= (3, 8):
class E:
def f(self): ...

class F:
def f(self): ...

class G: ...
class H: ...

0 comments on commit a49f3c3

Please sign in to comment.