blue icon indicating copy to clipboard operation
blue copied to clipboard

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

Open stefanoborini opened this issue 2 years ago • 3 comments

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)

stefanoborini avatar Dec 22 '22 09:12 stefanoborini

@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 avatar Apr 19 '23 13:04 jni

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

jni avatar Apr 19 '23 13:04 jni

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.

jsh9 avatar May 03 '23 10:05 jsh9