46

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.

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"
]

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.

3
  • 3
    Today (I have no idea since when), adding # type: ignore to the end of those lines flagged MissingImport by Pylance suppresses the error. This is obviously Not Quite Right and may not last. Commented Mar 18, 2023 at 15:39
  • 1
    To clarify, # type: ignore is extremely helpful in cases where the Linter is not advanced enough to see it is wrong. Commented Oct 28, 2023 at 17:43
  • @NilsLindemann it still works thank you. I had an issue with GlinerSpacy, but Vscode wasn't detecting it. This solved my issue Commented May 27, 2024 at 15:58

1 Answer 1

96
  1. Find the error-message you want to modify/disable in the Pylance's Diagnostic Severity Rules (in my case "reportMissingImports")
  2. Modify settings.json with "reportMissingImports": "none" (see diagnosis reporting levels in Pylance's Settings and Customization)

The entire JSON-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 use:

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

PS: regarding the settings.json - location

Along with the global settings.json there are also local versions in your VS-Code-projects' parent directories. In the following, example paths are provided based on my Windows 10 - OS:

  • global: C:\Users\user.name\AppData\Roaming\Code\User\settings.json
  • local: .vscode/settings.json

These local project settings override the global ones, if desired.

Sign up to request clarification or add additional context in comments.

4 Comments

It works perfectly. Notice that settings.json is located within ./vscode folder.
Thanks for pointing out the fact that there are various settings.jsons in VS Code, @BrunoL. I added this in a comment below my initial post.
this was driving me nuts! thank you. btw, cursor (vscode fork) stores it's settings under $HOME/.cursor/extensions/ms-python.vscode-pylance-2023.10.40 or via the extensions GUI
Thai works too "python.analysis.diagnosticSeverityOverrides": { "reportUndefinedVariable": "none" }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.