Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuation lines defined by extra indentation #89

Open
flexatone opened this issue Dec 19, 2022 · 1 comment
Open

Continuation lines defined by extra indentation #89

flexatone opened this issue Dec 19, 2022 · 1 comment

Comments

@flexatone
Copy link

Thank you for starting this project!

For a very long time I have been using an extra indent to distinguish continuation lines. This is defined as an option in PEP 8:

# Correct:

# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
                         var_three, var_four)

# 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)

# Hanging indents should add a level.
foo = long_function_name(
    var_one, var_two,
    var_three, var_four)

I use this consistently for function definitions or any other line continuation. The rule is simple, and I find it significantly helps in distinguishing line continuations from blocks of code created by loops, branches, function/class definitions, etc. This is a silly example but it conveys the idea:

def foo(
        a: int, # argument indented twice to distinguish from body of function
        b: float,
        ):
    c = a + b
    if (c >  20 
            or a < 0  # line continuation indented to distinguish body of `if`
            or b > 3): 
        c *= 2 
    d = bar(a=a,  
            b=b, # line continuation from function call
            c=c,
            )
    return d

Real code examples can be seen here:

https://github.com/static-frame/static-frame/blob/master/static_frame/core/series.py

I have not used black because it eliminates the information provided by these extra indents. I would be thrilled if blue might support this. I could work on a PR if there is interest.

@jsh9
Copy link

jsh9 commented May 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants