根据 PEP 8 正确的换行格式?

Proper line-break formatting according to PEP 8?

根据 PEP 8,这是可以接受的(以及我过去使用的):

result = some_function_that_takes_arguments(
    'a', 'b', 'c',
    'd', 'e', 'f',
)  

我的问题是,这是否也适用于函数定义,例如:

def some_function_that_takes_arguments(
    a, b, c,
    d, e, f,
):
    return a,b,c,d,e,f  

我过去做过的另一个例子:

if (this_is_one_thing
    and that_is_another_thing
):
    do_something()

我这样做已经有一段时间了(为了保持一致性,我所有 >79 col 的行都是这样分割的)并且想知道其他人的想法是什么。

这个clear/nice要看吗?这是否符合 PEP 8?

根据 PEP8 上的 doc 是的。只要缩进级别为 4 个空格,将函数声明拆分为 multi-line 就可以了。

Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent [7]. When using a hanging indent the following should be considered; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line.

Yes:

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

# More indentation included to distinguish this 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)

附带说明一下,如果您发现函数签名由于参数数量而变长,请考虑将您的函数分解为更多原子单元(因此遵守简洁代码原则).