-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
T: styleWhat do we want Blackened code to look like?What do we want Blackened code to look like?
Description
#2736 added a rule that preserves a blank line between attributes and methods. The implementation looks at the previous line instead of the previous statement, so it depends on the last statement in the (potentially arbitrarily nested) body if black inserts a blank line or not (code). #2783/#3564 fixes this for classes by always inserting a blank line, but this does not apply e.g. to function definitions. This affects e.g. typeshed, which uses if sys.version_info > (3, x): in stub files a lot.
I propose to change this to look at the type of the previous statement instead of the previous line.
Preview style
import sys
if sys.version_info > (3, 7):
class Nested1:
assignment = 1
def function_definition(self): ...
def f1(self) -> str: ...
class Nested2:
def function_definition(self): ...
assignment = 1
def f2(self) -> str: ...
if sys.version_info > (3, 7):
def nested1():
assignment = 1
def function_definition(self): ...
def f1(self) -> str: ...
def nested2():
def function_definition(self): ...
assignment = 1
def f2(self) -> str: ...Desired style
(or a different set of blank line rules that don't inspect the previous function body anymore)
import sys
if sys.version_info > (3, 7):
class Nested1:
assignment = 1
def function_definition(self): ...
def f1(self) -> str: ...
class Nested2:
def function_definition(self): ...
assignment = 1
def f2(self) -> str: ...
if sys.version_info > (3, 7):
def nested1():
assignment = 1
def function_definition(self): ...
def f1(self) -> str: ...
def nested2():
def function_definition(self): ...
assignment = 1
def f2(self) -> str: ...Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
T: styleWhat do we want Blackened code to look like?What do we want Blackened code to look like?