python-lsp / pylsp-mypy

Mypy plugin for the Python LSP Server.
MIT License
118 stars 35 forks source link

[Feature Request] Support dmypy `--status-file` flag #47

Closed Jasha10 closed 1 year ago

Jasha10 commented 1 year ago

Hello,

I'd like to request support for setting the dmypy --status-file flag via the pylsp-mypy.cfg file.

The use case is to ensure that multiple instances of the dmypy server do not collide with eachother.

Desired behavior:

Setting e.g. "dmypy_status_file": ".dmypy-pylsp.json" in the pylsp-mypy.cfg file should cause this plugin's invocations of dmypy to pass an argument --status-file=.dmypy-pylsp.json.

Jasha10 commented 1 year ago

One might think that the overrides key in the .pylsp-mypy.cfg could handle this use-case, but it does not, because the overrides are not consistently applied for all calls to dmypy. For example, the calls mypy_api.run_dmypy(["status"]) and mypy_api.run_dmypy(["kill"]) in this plugin's pylsp_lint function do not take into account the overrides.

The --status-file argument would need to be passed in consistently across all calls to dmypy.

Richardk2n commented 1 year ago

So passing the overrides consistently would also resolve this?

Jasha10 commented 1 year ago

I do not think the overrides should be passed consistently.

Overrides that work with dmypy run -- src will not always work with dmypy status and dmypy kill. For example, dmypy run -- src --check-untyped-defs makes sense but dmypy kill --check-untyped-defs does not make sense.

Also, the --status-file flag needs to be passed to dmypy before the status or kill or run argument:

dmypy --status-file=foo run -- src  # this works
dmypy run --status-file=foo -- src  # this fails with an error
dmypy run -- src --status-file=foo  # this fails with an error

We would need to implement a separate dmypy_overrides configuration parameter that gets always passed to dmypy calls, even when the more general overrides parameter does not apply.

    ...
    # passing dmypy_overrides only:
    mypy_api.run_dmypy([*dmypy_overrides, "status"])
    ...
    # killing the daemon:
    mypy_api.run_dmypy([*dmypy_overrides, "kill"])
    ...
    # passing both dmypy_overrides and normal args+overrides:
    mypy_api.run_dmypy([*dmypy_overrides, "run", "--", *run_args])
Jasha10 commented 1 year ago

@Richardk2n I'd be happy to open a PR implementing dmypy_overrides.

Richardk2n commented 1 year ago

Are there such overrides other than the status file that are relevant and are passed in this matter?

(asking for if we should implement and overrides dict or just the flag)

Jasha10 commented 1 year ago

Good question. After looking through the other dmypy flags (here's a full list), I think only the --status-file flag makes sense to pass in this manner.