Allow empty lines at beginnings of more blocks (#4130)
Fixes #4043, fixes #619 These include nested functions and methods. I think the nested function case quite clearly improves readability. I think the method case improves consistency, adherence to PEP 8 and resolves a point of contention.
This commit is contained in:
parent
c35924663c
commit
fe3376141c
@ -17,6 +17,8 @@
|
||||
- Format module docstrings the same as class and function docstrings (#4095)
|
||||
- Fix bug where spaces were not added around parenthesized walruses in subscripts,
|
||||
unlike other binary operators (#4109)
|
||||
- Address a missing case in the change to allow empty lines at the beginning of all
|
||||
blocks, except immediately before a docstring (#4130)
|
||||
|
||||
### Configuration
|
||||
|
||||
|
@ -745,7 +745,10 @@ def _maybe_empty_lines_for_class_or_def( # noqa: C901
|
||||
if self.previous_line.depth < current_line.depth and (
|
||||
self.previous_line.is_class or self.previous_line.is_def
|
||||
):
|
||||
return 0, 0
|
||||
if self.mode.is_pyi or not Preview.allow_empty_first_line_in_block:
|
||||
return 0, 0
|
||||
else:
|
||||
return 1 if user_had_newline else 0, 0
|
||||
|
||||
comment_to_add_newlines: Optional[LinesBlock] = None
|
||||
if (
|
||||
|
@ -39,6 +39,7 @@ def test_func(self):
|
||||
|
||||
|
||||
class ClassWithEmptyFunc(object):
|
||||
|
||||
def func_with_blank_parentheses():
|
||||
return 5
|
||||
|
||||
|
@ -62,6 +62,15 @@ def method(self):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def top_level(
|
||||
a: int,
|
||||
b: str,
|
||||
) -> Whatever[Generic, Something]:
|
||||
|
||||
def nested(x: int) -> int:
|
||||
pass
|
||||
|
||||
# output
|
||||
|
||||
def foo():
|
||||
@ -123,6 +132,16 @@ def quux():
|
||||
|
||||
|
||||
class Cls:
|
||||
|
||||
def method(self):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def top_level(
|
||||
a: int,
|
||||
b: str,
|
||||
) -> Whatever[Generic, Something]:
|
||||
|
||||
def nested(x: int) -> int:
|
||||
pass
|
||||
|
@ -203,6 +203,7 @@ def bar(a=1, b: bool = False):
|
||||
|
||||
|
||||
class Baz:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user