grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
387 stars 21 forks source link

Comply with PEP-8 for indentation of parameters in function definition #90

Open stefanoborini opened 1 year ago

stefanoborini commented 1 year ago

This:

def very_important_function(
    template: str,
    *variables,
    file: os.PathLike,
    debug: bool = False,
):
    code
    code

Should be formatted like this

def very_important_function(
        template: str,
        *variables,
        file: os.PathLike,
        debug: bool = False,
    ):
    code
    code

To comply with PEP-8 indentation directives:

# 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)
jni commented 1 year ago

@stefanoborini I'm 👍 on this but I do want to point out that your formatting suggestion actually does not comply with PEP8:

The closing brace/bracket/parenthesis on multiline constructs may either line up under the first non-whitespace character of the last line of list, as in: [...] or it may be lined up under the first character of the line that starts the multiline construct, as in: [...]

Not that I blame you, I do actually quite like that construct. But in the spirit of following PEP8 — it bugs me that black explicitly breaks with it so I shouldn't be tempted to do the same when convenient — I think it should be:

def very_important_function(
        template: str,
        *variables,
        file: os.PathLike,
        debug: bool = False,
        ):
    code
    code

This is how I've configured my yapf style. But yapf is no longer maintained. 😭

jni commented 1 year ago

Ah, note that this is actually a duplicate of #89

jsh9 commented 1 year ago

This particular style choice of Black also troubles me. That's what motivated me to start a more configurable formatter based on a fork from Black: https://github.com/jsh9/cercis

My project already supports indenting by 8 spaces at function definitions. And I plan to add more configurable options.

Please feel free to try it out and provide feedback.