mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.94k stars 204 forks source link

fix(mypy): make mypy respect the current python environment #627

Closed rainx0r closed 1 month ago

rainx0r commented 2 months ago

At the moment, the plugin will just run the global mypy, which, if installed via mason, will then only use system-level python3. If the user hasn't installed mypy through mason but has mypy installed in their locally activated python environment, it works fine though but I feel that's a bit suboptimal as you then need to install mypy into every custom environment you make.

To fix this I initially added the following to my nvim-lint config block:

      vim.list_extend(lint.linters.mypy.args, {
        '--python-executable',
        function()
          return vim.fn.exepath 'python3' or vim.fn.exepath 'python'
        end,
      })

and this works pretty much perfectly and should also work cross platform with basically any virtual env management system. This PR simply integrates this into the mypy configuration in nvim-lint.