自动保存在VS代码中Python的注释和函数头之间添加两个空行

vyt*_*ute 5 python formatting visual-studio-code pylance

我在 VS Code 中用 Python 编写代码。如果我在函数之前添加注释并点击保存按钮,VS code 将添加两个空行:

# comment


def MyMethod():
    return 0
Run Code Online (Sandbox Code Playgroud)

在设置中我看到我使用 autopep8 格式化程序: autopep8 格式化程序

我无法找到导致这个恼人问题的原因。也许我可以在某处配置设置?

Chr*_*her 2

记录函数行为的注释应放置在函数内部,位于签名下方。如果它不是描述函数(放置在函数之外),那么它应该有那些空行。不要破坏语言的约定,这是非常糟糕的主意。

编辑,进一步澄清:

"""Module-level comment
"""


def function(): 
    """Function level comment. 
    There are multiple conventions explaining how
    a comment's body should be formed.
    """
    return 0

Run Code Online (Sandbox Code Playgroud)