[英]VS Code Python + Black formatter arguments - python.formatting.blackArgs
I'm using the May 2018 Python extension (released June 2018) for VS Code 1.23.1 on Windows, python 3.6 via Anaconda, conda installing black from conda-forge into my conda environment.我在 Windows 上使用 VS Code 1.23.1 的 2018 年 5 月 Python 扩展(2018 年 6 月发布),通过 Anaconda 使用 python 3.6,conda 将黑色从 conda-forge 安装到我的 conda 环境中。
In my user settings.json I have the below:在我的用户 settings.json 中,我有以下内容:
"python.formatting.blackArgs": [
"--line-length 80"
],
which I'd think would be the correct way to structure this to pass arguments to black in VS Code Python formatting.我认为这是构建它以在 VS Code Python 格式中将参数传递给 black 的正确方法。
However, in my python Output pane I get the below:但是,在我的 python 输出窗格中,我得到以下信息:
Formatting with black failed.
Error: Error: no such option: --line-length 80
EDIT: If I edit my settings.json to be no args, such as:编辑:如果我将 settings.json 编辑为没有参数,例如:
"python.formatting.blackArgs": [],
black works as expected.黑色按预期工作。
Does anyone know how to pass arguments correctly to the new (as of June 2018) black formatter?有谁知道如何将参数正确传递给新的(截至 2018 年 6 月)黑色格式化程序?
The examples of formatter-specific settings show the following: 特定于格式化程序的设置示例显示如下:
"python.formatting.autopep8Args": ["--max-line-length", "120", "--experimental"],
"python.formatting.yapfArgs": ["--style", "{based_on_style: chromium, indent_width: 20}"]
So try:所以尝试:
"python.formatting.blackArgs": ["--line-length", "80"]
The proper way to config in the Settings GUI pane is with --line-length
and the desired value as separate items:在设置 GUI 窗格中进行配置的正确方法是将
--line-length
和所需的值作为单独的项目:
Visual Studio Code GUI Settings for Python Formatting用于 Python 格式的 Visual Studio Code GUI 设置
This converts into the settings.json into this:这将转换为 settings.json 成:
Visual Studio Code JSON Settings for Python Formatting用于 Python 格式的 Visual Studio Code JSON 设置
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length", "110"]
My setting is: "python.formatting.blackArgs": ["--line-length=110"]
and it's working correctly.我的设置是:
"python.formatting.blackArgs": ["--line-length=110"]
并且它工作正常。 The equal sign was missing in your user settings.json您的用户 settings.json 中缺少等号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.