-
Notifications
You must be signed in to change notification settings - Fork 23
Description
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.