| Crates.io | dmypyls |
| lib.rs | dmypyls |
| version | 0.2.2 |
| created_at | 2024-11-12 02:12:13.549459+00 |
| updated_at | 2024-11-14 16:00:34.92856+00 |
| description | A language server to support editor agnostic usage of the dmypy daemon. |
| homepage | https://github.com/wbbradley/dmypyls |
| repository | https://github.com/wbbradley/dmypyls |
| max_upload_size | |
| id | 1444477 |
| size | 56,210 |
/ˈdɪmpəlz/
dmypyls is a language server for mypy that leverages the dmypy daemon. dmypyls manages the
life-cycle of the dmypy daemon and provides a language server interface to it.
I'm following this issue for more info on a straight mypy language server implementation.
cargo install dmypyls.dmypyls to your editor's language server configuration. (See below for Neovim example.)Consider using dmypyls-debug-runner to run from source, which is helpful for
development purposes.
In order to allow dmypyls to find the correct mypy configuration, you should place a dmypyls.yaml file
in the root of your project as a sibling to mypy.ini or pyproject.toml. Here are some example configurations:
If you manage your python environment with venv or uv, you'll probably want your configuration
to look like this:
# dmypyls.yaml
dmypy_command:
- .venv/bin/dmypy
If you manage your virtual environment with pipenv:
# dmypyls.yaml
dmypy_command:
- pipenv
- run
- dmypy
Or uv:
# dmypyls.yaml
dmypy_command:
- uv
- --quiet
- run
- dmypy
Or pdm:
# dmypyls.yaml
dmypy_command:
- pdm
- --quiet
- run
- dmypy
You can place a dmypyls.yaml in your "$HOME"/.config/dmypyls directory to configure a fallback
behavior for all projects.
vim.api.nvim_create_autocmd({ "BufRead" }, {
pattern = { "*.py" },
group = vim.api.nvim_create_augroup("dmypyls-bufread", { clear = true }),
callback = function(_)
if vim.fn.executable("dmypyls") ~= 0 then
-- We found an executable for dmypyls.
vim.lsp.set_log_level(vim.log.levels.INFO)
vim.lsp.start({
name = "dmypyls",
cmd = { "dmypyls", vim.api.nvim_buf_get_name(0) },
root_dir = vim.fs.root(0, {
".git",
"pyproject.toml",
"setup.py",
"mypy.ini"
})
}, { bufnr = 0, reuse_client = function(_, _) return false end })
end
end
})
In order for mypy usage to be helpful, I recommend ramping up the strictness of its checks. Here is
an example mypy.ini with relatively strict configuration.
[mypy]
strict_optional = True
show_error_codes = True
pretty = True
warn_redundant_casts = True
warn_unused_ignores = True
ignore_missing_imports = False
check_untyped_defs = True
disallow_untyped_defs = True
disallow_any_unimported = True
no_implicit_optional = True
warn_return_any = True