简体   繁体   English

如何在 VS Code 中为 Python 启用 Intellisense 但通过 Pylance 禁用 Linting?

[英]How to enable Intellisense for Python in VS Code but Disable Linting by Pylance?

Related post 相关帖子

The above post asks how to disable linting in VS Code by Pylance.上面的帖子询问了如何通过 Pylance 在 VS Code 中禁用 linting。 This proposed setting works:这个建议的设置有效:

"python.languageServer": "None"

But it also disables features like Intellisense and Go to Definition .但它也会禁用诸如IntellisenseGo 之类的功能到 Definition I want to keep those features working and disable the automatic linting done by Pylance as I'm actively writing out code.我想保持这些功能正常工作并禁用 Pylance 完成的自动 linting,因为我正在积极编写代码。 It's very distracting.这很让人分心。

Note that setting "python.linting.enabled": false doesn't work;请注意,设置"python.linting.enabled": false不起作用; Pylance still points out "problems" in code the moment I stop typing.在我停止打字的那一刻,Pylance 仍然指出代码中的“问题”。

I also don't want to disable linting entirely, I just want to have more control over when my files are linted (like getting warnings after saving).我也不想完全禁用 linting,我只想更好地控制我的文件何时被 linting(比如保存后收到警告)。 I'm also using other programs like flake8 and bandit which provide the functionality I need and can be shut off until I'm ready to check my code.我还在使用其他程序,例如flake8bandit ,它们提供了我需要的功能,并且可以关闭,直到我准备好检查我的代码。

Update:更新:

I found a way to disable specific Pylance warnings by referencing this document in pylance-release.通过在 pylance-release 中引用此文档,我找到了一种禁用特定 Pylance 警告的方法。 Setting a rule to none disables warnings for that rule.将规则设置为none会禁用该规则的警告。 I added the following to my settings.json:我在settings.json 中添加了以下内容:

   "python.analysis.diagnosticSeverityOverrides": {
        "reportUnboundVariable": "none",
        "reportUndefinedVariable": "none",
        "reportMissingImports": "none",
        "reportMissingModuleSource": "none",
    }

I did not however find a way to disable syntax error warnings.但是,我没有找到禁用语法错误警告的方法。

Open the command palette using Ctrl + Shift + P and type in linting.使用Ctrl + Shift + P打开命令面板并输入 linting。 You should have 2 options你应该有2个选项1 It's pretty self explanatory from here.从这里可以很好地自我解释。

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

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