如何在VSCode中使用yapf

问题描述 投票:0回答:1

我使用以下方法安装了yap​​f:

conda install yapf

并在.vscode/settings.json文件中添加下一行:

{
    //"python.linting.pylintEnabled": true,
    //"python.linting.pycodestyleEnabled": false,
    //"python.linting.flake8Enabled": true,
    "python.formatting.provider": "yapf",
    "python.formatting.yapfArgs": [
        " — style",
        "{based_on_style: pep8, indent_width: 4}"
    ],
    "python.linting.enabled": true,
}

但是我不明白如何使用它-它在具有错误但代码风格的文件中不显示任何错误:

import pandas as pd

class MyClass(object):
    def __init__(self, some_value: int):
        self.value = some_value
    def one_more_function(self, another_value):
        print(another_value)
myObject = MyClass(45)
myObject.one_more_function(2)
my__object2 = MyClass(324)

    print('ok')
def some_foo():
    """
    """
    pass
python-3.x visual-studio-code intellisense pylint yapf
1个回答
0
投票

问题出在错误的设置中。要使用yapf,black或autopep8,您需要:

  1. 安装yapf /黑色/ autopep8(点安装黑色)
  2. 以以下方式配置.vscode/settings.json

文件的一部分:

{
    "python.linting.enabled": true,
    "python.linting.pylintPath": "pylint",
    "editor.formatOnSave": true,
    "python.formatting.provider": "black",
    "python.linting.pylintEnabled": true,
}

关键选项-"editor.formatOnSave": true,,这意味着yapf每次保存时都会格式化您的文档。

© www.soinside.com 2019 - 2024. All rights reserved.