admin管理员组

文章数量:1246701

I'm using VSCode with the mypy plugin in my Django project. My pyproject.toml configuration looks like this (following the Django Stubs README):

[tool.mypy]
mypy_path = "."
python_version = "3.13"
strict = true
plugins = ["mypy_django_plugin.main"]

[tool.django-stubs]
django_settings_module = "conf.settings"

When I run mypy in the terminal, everything works fine, and I get proper type checking.

However, in VSCode, I don't get any type hints at all. If I comment out the plugins line, mypy starts working in VSCode again.

What I've Tried:

  1. Running mypy manually in the terminal → Works as expected
  2. Commenting out plugins → VSCode starts showing hints again
  3. Checking that VSCode uses the correct mypy config (it's picking up pyproject.toml)

Any insights would be greatly appreciated!

EDIT: Using VSCode inside my Docker container via Remote Exploxer works. So I guess Django needs to be booted in my VSCode environment for the mypy plugins to work properly. It would be nice to have a workaround though.

EDIT2: I found this error message in the VSCode Output terminal:

django.core.exceptions.ImproperlyConfigured: 'django.db.backends.None' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of: 'mysql', 'oracle', 'postgresql', 'sqlite3' 

本文标签: pythonVSCode Ignores Mypy Type Hints When Using Django PluginsStack Overflow