Blog

It's minimal, but I'm posting things.


Disabling typehint diagnostics for pyright-langserver in Vim

Coding some Python in Vim is enhanced by the use of a LSP (language server protocol) specific to Python.
After some trial and error (there are many LSPs for Python), I find pyright from Microsoft to be the most pleasing.

However, by default, the typehint analysis is too verbose and too strict for my purpose.
Here is how you can disable most disagnostics relative to typehints for pyright.

This assumes you are using the helpful mattn/vim-lsp-settings plugin for Vim.
If not, this page should still give you pointers.

Customize your global lsp-settings.json file

In your configuration file, add something similar to the following, customizing where you'd like the settings file to be.

let g:lsp_settings_global_settings_dir = expand('~') . "/.lsp-settings.json"

This is what I have inside my .lsp-settings.json file:

{
  "pyright-langserver": {
    "args": [
      "--stdio",
      "-p ~/.pyrightconfig-global.json"
    ]
  }
}

The -p argument allows us to specify which .pyrightconfig to load when the pyright lsp starts up.

By default, pyright only read a .pyrightconfig file at the root of every project. This solution allows us to have a global settings file.

Customize your .pyrightconfig-global.json file

The full documentation for the values you may customize is available: https://github.com/microsoft/pyright/blob/1f42e17eb3a036271dd17b79a7eb5593c10aae46/docs/configuration.md

The contents of my .pyrightconfig-global.json file are:

{
  "exclude": [
    "**/node_modules",
    "**/__pycache__"
  ],
  "pythonVersion": "3.10",
  "pythonPlatform": "Linux",
  "reportMissingImports": true,
  "reportMissingTypeStubs": false,
  "verboseOutput": true,
  "typeCheckingMode": "off"
}

The most important setting for us is: "typeCheckingMode": "off"

As per the documentation:

The default value for this setting is "basic". If set to "off", all type-checking rules are disabled, but Python syntax and semantic errors are still reported.

That's it!


Published on 2025-02-28T15:58:58.843985Z
Last updated on 2025-02-28T15:58:58.843985Z