2

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?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
mrkbutty
  • 489
  • 1
  • 5
  • 13
  • Hi Jill thanks for the suggestion but I want to selectively pick out variables to exclude from the check. – mrkbutty Feb 06 '21 at 01:24
  • I have submitted this proposal and let us look forward to a good solution. Github link: [Is there a setting to turn off specific errors displayed by Pylance](https://github.com/microsoft/pylance-release/issues/929) – Jill Cheng Feb 09 '21 at 02:42

2 Answers2

7

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

informatik01
  • 16,038
  • 10
  • 74
  • 104
Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
3

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.

dlindsay
  • 105
  • 7