繁体   English   中英

VS Code Python + 黑色格式化程序参数 - python.formatting.blackArgs

[英]VS Code Python + Black formatter arguments - python.formatting.blackArgs

我在 Windows 上使用 VS Code 1.23.1 的 2018 年 5 月 Python 扩展(2018 年 6 月发布),通过 Anaconda 使用 python 3.6,conda 将黑色从 conda-forge 安装到我的 conda 环境中。

在我的用户 settings.json 中,我有以下内容:

"python.formatting.blackArgs": [
    "--line-length 80"
],

认为这是构建它以在 VS Code Python 格式中将参数传递给 black 的正确方法。

但是,在我的 python 输出窗格中,我得到以下信息:

Formatting with black failed.
Error: Error: no such option: --line-length 80

编辑:如果我将 settings.json 编辑为没有参数,例如:

"python.formatting.blackArgs": [],

黑色按预期工作。

有谁知道如何将参数正确传递给新的(截至 2018 年 6 月)黑色格式化程序?

问题在于,对于 1.38.1 及更高版本,您需要在--line-length之后使用=80而不是80

--line-length=80  

在此处输入图片说明

特定于格式化程序的设置示例显示如下:

"python.formatting.autopep8Args": ["--max-line-length", "120", "--experimental"],
"python.formatting.yapfArgs": ["--style", "{based_on_style: chromium, indent_width: 20}"]

所以尝试:

"python.formatting.blackArgs": ["--line-length", "80"]

在设置 GUI 窗格中进行配置的正确方法是将--line-length和所需的值作为单独的项目:

用于 Python 格式的 Visual Studio Code GUI 设置

这将转换为 settings.json 成:

用于 Python 格式的 Visual Studio Code JSON 设置

"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length", "110"]

我的设置是: "python.formatting.blackArgs": ["--line-length=110"]并且它工作正常。 您的用户 settings.json 中缺少等号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM