Search code examples
visual-studio-codepylance

How can I see the default values for the Python Diagnostic Severity Rules in VS Code?


How can I see (or extract in a JSON file) the default values for the Diagnostic Severity Rules for Python in VS Code, as described here? https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules


Solution

  • If you just need to see the default value in VS Code, just open the settings.json file (User or Workspace), and enter each of those keys one by one. A popup should appear for each possible value, and the default value will have a "Default value" hint in the description.

    settings UI

    enter setting

    see default value hint

    You can also check the Pylance extension's directory installed on your machine. First, find the directory for all your VS Code extensions:

    Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder:

    • Windows %USERPROFILE%\.vscode\extensions
    • macOS ~/.vscode/extensions
    • Linux ~/.vscode/extensions

    Go to that folder, and look for the ms-python.vscode-pylance* folder.

    $ cd ~/.vscode/extensions/
    
    extensions$ tree . -L 1 | grep "ms-python.vscode-pylance"
    ├── ms-python.vscode-pylance-2021.10.0
    
    extensions$ cd ms-python.vscode-pylance-2021.10.0
    
    ms-python.vscode-pylance-2021.10.0$ tree -L 1 .
    .
    ├── CHANGELOG.md
    ├── LICENSE.txt
    ├── NOTICE.txt
    ├── README.md
    ├── dist
    ├── images
    ├── package.json
    ├── package.nls.json
    └── package.nls.ru.json
    

    Open the package.json, and somewhere under configuration > properties > python.analysis.diagnosticSeverityOverrides, you'll find all those rules with their default values:

    ...
    "reportMissingImports": {
        "type": "string",
        "description": "Diagnostics for imports that have no corresponding imported python file or type stub file.",
        "default": "warning",
        "enum": [
                "none",
                "information",
                "warning",
                "error"
        ]
    },
    "reportMissingModuleSource": {
        "type": "string",
        "description": "Diagnostics for imports that have no corresponding source file. This happens when a type stub is found, but the module source file was not found, indicating that the code may fail at runtime when using this execution environment. Type checking will be done using the type stub.",
        "default": "warning",
        "enum": [
                "none",
                "information",
                "warning",
                "error"
        ]
    },
    "reportMissingTypeStubs": {
        "type": "string",
        "description": "Diagnostics for imports that have no corresponding type stub file (either a typeshed file or a custom type stub). The type checker requires type stubs to do its best job at analysis.",
        "default": "warning",
        "enum": [
                "none",
                "information",
                "warning",
                "error"
        ]
    },
    ...
    

    The default value is in the default key. (Notice the default for reportMissingImports matches the one in the screenshot from the settings.json popup.

    That's already a JSON file, if you need to extract it to JSON format.