'Is it possible to set lint custom settings and ignores for pylance

Previously when using pylint I have have used custom comment settings to ignore undefined vars when editing in vscode, for example:

# Make pylint think that it knows about additional builtins
data = data  # pylint:disable=invalid-name,used-before-assignment,undefined-variable
DEBUG = DEBUG # pylint:disable=invalid-name,used-before-assignment,undefined-variable
VERBOSE = VERBOSE # pylint:disable=invalid-name,used-before-assignment,undefined-variable

Note my application has it's own python based cut down scripting language hence the additional builtins.

I've not been able to find an equivalent for pylance. Anyone have any suggestions?



Solution 1:[1]

You can add the following settings in settings.json configuration file:

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

Or you can search for python.analysis.diagnosticSeverityOverrides in the settings, click Add Item button to select "reportUndefinedVariable", "none":

enter image description here

Result:

enter image description here

Solution 2:[2]

Following the issue that @Jill Cheng linked in the comments, the pylance devs suggest using a # type: ignore comment after the line in question. You will lose out on other linting abilities for this line though so apply with caution.

As a side note, if you're using this to quiet the messages due to "import <module> could not be resolved" then you should look into correctly configuring your workspace rather than overriding the message. Here's an example answer to help you solve that issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 informatik01
Solution 2 dlindsay