为什么 VS-Code Autopep8 会格式化 2 条白线?

Why does VS-Code Autopep8 format 2 white lines?

print("Hello")

def world():
    print("Hello")

world()

更正为:

print("Hello")


def world():
    print("Hello")


world()

我尝试过:

因为 autopep8 跟在 PEP8 之后,这表明顶级函数周围有 2 个空行。

Surround top-level function and class definitions with two blank lines.

您可以通过在 .vscode/settings.json

中使用以下配置来禁用此功能
{
    "python.formatting.provider": "autopep8",
    "python.formatting.autopep8Args": [
        "--ignore=E302"
    ]
}

以下是所有 autopep8 功能的解释:https://github.com/hhatto/autopep8#features