在 VS Code settings.json 中禁用特定的 Pylance linting 消息,就像 "python.linting.pylintArgs"

Disable specific Pylance linting messages in VS Code settings.json like with "python.linting.pylintArgs"

Pylance was introduced, I filed a on how to generally customize Pylance linting. Here 时,可以找到一些自定义 Pylance 的方法,但没有关于如何抑制、静音或实际禁用某些警告和错误的方法。

回顾一下,使用 pylint 可以在 VS Code settings.json 中指定以下内容以禁用某个 error/warning:

"python.linting.pylintArgs": [
    "--disable=C0111"
]

至于背景,自excessive Pylance(reportMissingImports) linting errors has not been resolved yet and due to project requirements, I've enabled pylint simultaneously with Pylance。尽管如此,这些无数的 Pylance(reportMissingImports) linting 错误还是很烦人,我想完全消除它们。

  1. 获取您想要的错误消息值 modify/disable here(在我的例子中是“reportMissingImports”)
  2. settings.json修改为"reportMissingImports": "none"(见诊断报告级别here

要插入 settings.json 的整个代码是:

"python.analysis.diagnosticSeverityOverrides": {
    "reportMissingImports": "none"
}

顺便说一句,如果你想至少了解未使用的导入,你可以插入:

"python.analysis.diagnosticSeverityOverrides": {
    "reportUnusedImport": "information",
    "reportMissingImports": "none"
}