-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
T: styleWhat do we want Blackened code to look like?What do we want Blackened code to look like?
Description
Currently, black reformats long routine names as follow
# in:
def very_important_function(template: str, *variables, file: os.PathLike, engine: str, header: bool = True, debug: bool = False):
"""Applies `variables` to the `template` and writes to `file`."""
with open(file, 'w') as f:
...
# out:
def very_important_function(
template: str,
*variables,
file: os.PathLike,
engine: str,
header: bool = True,
debug: bool = False,
):
"""Applies `variables` to the `template` and writes to `file`."""
with open(file, "w") as f:
Desired style
The current style done by black violates pep8 recommendation
# Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
The logic and motivation behind pep8 formatting, and against black, is that one wants to keep the indentation of the function definition continuation at a different level compared to the logic block. Otherwise, it's harder to differentiate what's one and what's the other, despite the indented frowny face.
In fact, flake8 reports a pep8 violation for a case such as this
if path.suffix in (
'.js', '.json'
):
proto = Protocol.json
x.py:20:5: E125 continuation line with same indent as next logical line
Black current formatting would be equivalent to this
if path.suffix in (
'.js', '.json'
):
proto = Protocol.json
Which we can probably all agree is a bad idea.
Additional context from python-ideas mailing list
quassy, piotr-dobrogost, akashgurava, evanscottgray, Mattwmaster58 and 12 moreovidiu-munteanu, peterjc, mjrk, ellismg, fiendish and 10 more
Metadata
Metadata
Assignees
Labels
T: styleWhat do we want Blackened code to look like?What do we want Blackened code to look like?