VS Code Autopep8为什么会格式化两个空白行?

huangapple go评论82阅读模式
英文:

Why does VS-Code Autopep8 format 2 white lines?

问题

以下是已翻译好的内容:

print("Hello")

def world():
    print("Hello")

world()

请注意,这段代码看起来已经正确,没有需要修复的问题。如果您遇到任何其他问题,请提供更多详细信息以获取帮助。

英文:
print("Hello")

def world():
    print("Hello")

world()

Gets corrected to:

print("Hello")

def world():
    print("Hello")

world()

I have tried to:

  • Reinstall Virtual Studio Code
  • Reinstall Python 3.8
  • Computer Reboot
  • Using other formatters like Black and yapf but got the same result

答案1

得分: 4

因为autopep8遵循PEP8,该规范建议在顶级函数周围使用2个空行。

> 用两个空行包围顶级函数和类定义。

英文:

Because autopep8 follows PEP8 which suggests 2 blank lines around top-level functions.

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

答案2

得分: 4

你可以通过在你的 .vscode/settings.json 中使用以下配置来禁用它:

{
    "python.formatting.provider": "autopep8",
    "python.formatting.autopep8Args": [
        "--ignore=E302"
    ]
}

这里解释了所有 autopep8 的功能:https://github.com/hhatto/autopep8#features

英文:

You can disable this by using the following configuration in your .vscode/settings.json

{
    "python.formatting.provider": "autopep8",
    "python.formatting.autopep8Args": [
        "--ignore=E302"
    ]
}

Here are all the autopep8 features explained: https://github.com/hhatto/autopep8#features

答案3

得分: 0

你还可以在您的VS Code设置中配置python.formatting.autopep8Args

英文:

you can also configure python.formatting.autopep8Args under your vscode setting.

VS Code Autopep8为什么会格式化两个空白行?

huangapple
  • 本文由 发表于 2020年1月4日 00:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581746.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定