Make blank_line_after_nested_stub_class
work for methods (#4141)
Fixes #4113 Authored by dhruvmanila
This commit is contained in:
parent
b1d17ef9a2
commit
e11eaf2f44
@ -21,6 +21,7 @@
|
|||||||
- Remove empty lines before docstrings in async functions (#4132)
|
- Remove empty lines before docstrings in async functions (#4132)
|
||||||
- Address a missing case in the change to allow empty lines at the beginning of all
|
- Address a missing case in the change to allow empty lines at the beginning of all
|
||||||
blocks, except immediately before a docstring (#4130)
|
blocks, except immediately before a docstring (#4130)
|
||||||
|
- For stubs, fix logic to enforce empty line after nested classes with bodies (#4141)
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
|
@ -640,15 +640,15 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
|
|||||||
if previous_def is not None:
|
if previous_def is not None:
|
||||||
assert self.previous_line is not None
|
assert self.previous_line is not None
|
||||||
if self.mode.is_pyi:
|
if self.mode.is_pyi:
|
||||||
if depth and not current_line.is_def and self.previous_line.is_def:
|
if (
|
||||||
# Empty lines between attributes and methods should be preserved.
|
|
||||||
before = 1 if user_had_newline else 0
|
|
||||||
elif (
|
|
||||||
Preview.blank_line_after_nested_stub_class in self.mode
|
Preview.blank_line_after_nested_stub_class in self.mode
|
||||||
and previous_def.is_class
|
and previous_def.is_class
|
||||||
and not previous_def.is_stub_class
|
and not previous_def.is_stub_class
|
||||||
):
|
):
|
||||||
before = 1
|
before = 1
|
||||||
|
elif depth and not current_line.is_def and self.previous_line.is_def:
|
||||||
|
# Empty lines between attributes and methods should be preserved.
|
||||||
|
before = 1 if user_had_newline else 0
|
||||||
elif depth:
|
elif depth:
|
||||||
before = 0
|
before = 0
|
||||||
else:
|
else:
|
||||||
|
@ -18,6 +18,18 @@ def function_definition(self): ...
|
|||||||
assignment = 1
|
assignment = 1
|
||||||
def f2(self) -> str: ...
|
def f2(self) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
class TopLevel:
|
||||||
|
class Nested1:
|
||||||
|
foo: int
|
||||||
|
def bar(self): ...
|
||||||
|
field = 1
|
||||||
|
|
||||||
|
class Nested2:
|
||||||
|
def bar(self): ...
|
||||||
|
foo: int
|
||||||
|
field = 1
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -42,3 +54,16 @@ def function_definition(self): ...
|
|||||||
assignment = 1
|
assignment = 1
|
||||||
|
|
||||||
def f2(self) -> str: ...
|
def f2(self) -> str: ...
|
||||||
|
|
||||||
|
class TopLevel:
|
||||||
|
class Nested1:
|
||||||
|
foo: int
|
||||||
|
def bar(self): ...
|
||||||
|
|
||||||
|
field = 1
|
||||||
|
|
||||||
|
class Nested2:
|
||||||
|
def bar(self): ...
|
||||||
|
foo: int
|
||||||
|
|
||||||
|
field = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user