是否可以将默认元组/列表参数中的值设在同一行,但每个参数都设在换行符上?

Is it possible to have the values in default tuple/list parameters at same line, but have every parameter at newline?

提问人:Sombrero 提问时间:5/23/2023 更新时间:5/23/2023 访问量:32

问:

我有一个自动生成的文件,我运行它:

autopep8 --in-place --aggressive  --aggressive

问题是,对于默认元组,它们被分成多行,我希望每个元组都在自己的行上。例如:

def function(
        x="One upon a time, there was a young man wanting to use autopep8, but he doesn't seem to understand how it works",
        y="One upon a time, there was a young man wanting to use autopep8, but he doesn't seem to understand how it works", hello=(0,)):
    print(x)
    print(y)
    print(hello)

呈现为:

def function(
        x="One upon a time, there was a young man wanting to use autopep8, but he doesn't seem to understand how it works",
        y="One upon a time, there was a young man wanting to use autopep8, but he doesn't seem to understand how it works",
        hello=(
            0,
        )):
    print(x)
    print(y)
    print(hello)

(看参数),但我希望它是:hello

def function(
        x="One upon a time, there was a young man wanting to use autopep8, but he doesn't seem to understand how it works",
        y="One upon a time, there was a young man wanting to use autopep8, but he doesn't seem to understand how it works",
        hello=(0,)):
    print(x)
    print(y)
    print(hello)

这可能吗?

我尝试只运行单个,但这并没有将所有参数放在不同的行上,所以我假设这不是答案。此外,这些函数是自动生成的,因此很难预测每个变量的长度。 我知道当列表和/或元组非常长时,这是一个不错的功能,但是当列表/元组不超过“max-line-width”时,我不明白为什么它应该这样做。--aggressive

python-3.x 默认参数 autopep8

评论


答: 暂无答案