python-lsp / pylsp-mypy

Mypy plugin for the Python LSP Server.
MIT License
130 stars 37 forks source link

pylsp-mypy not recognizing correct Python version #87

Closed yanniskatsaros closed 3 months ago

yanniskatsaros commented 4 months ago

I have a Python 3.11.9 project (MacOS Sonoma 14.5 (23F79) - M1 Pro) configured using solely a pyproject.toml. I am using a venv with all project dependencies installed and LSP is working correctly in my editor (Helix) and pylsp-mypy is correctly showing typing errors/diagnostics in my editor. (Note: python-lsp-server and pylsp-mypy are both installed in this project's virtual environment.)

However, I am getting an LSP error in my editor when using structural pattern matching:

Pattern matching is only supported in Python 3.10 and greater (syntax)

When I manually run mypy in my terminal I do not get this error. I tried deleting the entire .mypy_cache directory as well and re-starting LSP etc. but this did not fix the issue.

The following is a snippet of relevant information found in my pyproject.toml:

# ... snip ...

[tool.mypy]
python_version = "3.11"
strict = true
plugins = [
  # https://docs.pydantic.dev/1.10/mypy_plugin/
  "pydantic.mypy",
]

# ... snip ...

[tool.pylsp-mypy]
enabled = true
live_mode = false
dmypy = false
strict = true
exclude = [
  "build",
  "**/.git",
  "**/.github",
  "**/.aws-sam",
  "**/.venv",
  "**/.vscode",
  "**/node_modules",
  "**/__pycache__",
  "**/.mypy_cache",
  "**/.ruff_cache",
]

I even tried the overrides attribute but without any success:

[tool.pylsp-mypy]
# ...
overrides = [
    "--python-version",
    "3.11",
]

I even checked the python-lsp-server configuration documentation did not find anything relevant to Python version configuration. Can anyone please help me out, is there something I have misconfigured or is this a bug?

Richardk2n commented 3 months ago

Are you sure, that this output is from mypy? There are likely other plugins running as well. The mypy section in your pyprojectl.toml looks fine to me.

yanniskatsaros commented 3 months ago

@Richardk2n you're right, I think this is actually an issue with python-lsp-ruff. I'll go ahead and close this and open an issue there. Sorry about that, thanks!