python-lsp / pylsp-mypy

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

Feature request: configuration to not check certain modules/files with mypy #67

Closed MrGreenTea closed 10 months ago

MrGreenTea commented 1 year ago

For example I don't want my test_ files littered with mypy diagnostics. For this reason my pyproject.toml looks something like this:

# pyproject.toml
[tool.mypy]
exclude = ["tests", 'test_.+\.py']

I propose to include this configuration option somehow and not run mypy on files that match a regex inside exclude. But I am open to other options as well if they make more sense or are easier to implement :)

MrGreenTea commented 1 year ago

I've built a first draft in my fork for setting this from the pylsp-mypy configuration. I would prefer also being able to read the configuration from the mypy configuration, but as this does not yet happen for anything else I am reluctant to add it.

Richardk2n commented 1 year ago

What is wrong with having this set in pyproject.toml?

MrGreenTea commented 1 year ago

What is wrong with having this set in pyproject.toml?

How do you mean that? I dont't see anything wrong with it. My issue is that I have set it for mypy in pyproject.toml as described in this issue. I'd love for pylsp-mypy to read that info from my pyproject.toml and not run mypy for my test files as currently I get a lot of diagnostics in my tests which makes it hard to work on and I often have to disable the pylsp-mypy plugin completely when writing tests.

As mentioned in the PR #68 I didn't implement reading in the mypy section from pyproject.toml because it would be something that the plugin does not yet do for anything else. Because of that my PR needs this to be set specifically for pylsp-mypy (and therefore duplicated from the mypy config).

Richardk2n commented 1 year ago

pylsp-mypy does detect the presence of a mypy section in the pyproject.toml and if present hands it to mypy.

Does that not cover what you intend to do, or does it not work?

maerteijn commented 11 months ago

Does that not cover what you intend to do, or does it not work?

@Richardk2n The exclude configuration inside pyproject.toml for mypy is correctly handed over to mypy, but it is not used when you invoke mypy on a single document. In other words: This exclude option is only used for discovering documents when running mypy on a whole directory. Which means there is currently not a way fot excluding mypy for a subset of files (eg tests, utility files etc.) with pylsp-mypy.

What @MrGreenTea introduced in #68 is actually a good workaround and simple solutiom by adding a separate setting to pylsp-mypy for this. I took the liberty to improve this a bit, see #71

Richardk2n commented 11 months ago

I see. This seems sensible.

Richardk2n commented 10 months ago

Completed with #71