问题描述
当引入 Pylance 时,我提交了一个 问题通常自定义 Pylance linting.这里,你可以找到一个自定义 Pylance 的方法很少,但没有关于如何抑制、静音或实际禁用某些警告和错误.
When Pylance was introduced, I filed a question on how to generally customize Pylance linting. Here, one can find a few ways to customize Pylance, but there is nothing about how to suppress, mute or actually disable certain warnings and errors.
回顾一下,使用 pylint 可以在 VS Code 设置中指定以下内容.json
禁用某个错误/警告:
As a recap, with pylint one can specify the following in VS Code settings.json
to disable a certain error/warning:
"python.linting.pylintArgs": [
"--disable=C0111"
]
至于背景,由于过多的 Pylance(reportMissingImports) linting 错误 尚未解决,由于项目要求,我已启用 pylint 与 Pylance 同步.尽管如此,这些无数的 Pylance(reportMissingImports) linting 错误很烦人,我想完全消除它们.
As for the background, since the excessive Pylance(reportMissingImports) linting errors has not been resolved yet and due to project requirements, I've enabled pylint simultaneously with Pylance. Still, these countless Pylance(reportMissingImports) linting errors are annoying and I'd like to silence them completely.
推荐答案
- 获取要修改/禁用的错误消息值此处(在我的例子中是reportMissingImports")
- 使用
"reportMissingImports":"none"
修改settings.json
(参见诊断报告级别此处)
- Get error-message value you want to modify/disable here (in my case "reportMissingImports")
- Modify
settings.json
with"reportMissingImports": "none"
(see diagnosis reporting levels here)
要插入到 settings.json
中的整个代码是:
The entire code to be inserted into the settings.json
is:
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingImports": "none"
}
顺便说一句,如果您想至少了解未使用的导入,您可以插入:
As an aside, if you want to be at least informed about unused imports, you can insert:
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedImport": "information",
"reportMissingImports": "none"
}
这篇关于在 VS Code settings.json 中禁用特定的 Pylance linting 消息,例如“python.linting.pylintArgs";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!