pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Installed stubs don't take precedence over bundled stubs

Open rchiodo opened this issue 2 years ago • 2 comments

See this issue #5027

  1. Install django-stubs into your environment
  2. Set typechecking mode to basic
  3. Add the following code to a file
from django.db import models

class MyModel(models.Model):
    nullable = models.IntegerField(null=True)

def foo():
    m = MyModel.objects.get()

    def accepts_only_int(x: int):
        pass

    accepts_only_int(m.nullable)
  1. If we actually used the django-stubs, passing m.nullable to accepts_only_int shouldn't show an error.
  2. If you goto declaration on models.IntegerField it will still jump into our bundled stubs.

rchiodo avatar Oct 27 '23 20:10 rchiodo

I am seeing the same behaviour:

Tested in v2023.20.0 and v2023.21.13141007 and in both cases Pylance is choosing the bundled stubs over the installed ones.

jmfederico avatar Nov 12 '23 10:11 jmfederico

It's a very annoying workaround, but what I'm doing in a devcontainer is as follows:

rm -rf ~/.vscode-server/extensions/ms-python.vscode-pylance-2023.12.1/dist/bundled/stubs/django-stubs

Then reloading the window causes Pylance to find the real django-stubs that were installed. There should be an option to disable the extension's bundled stubs.

basicdays avatar Jan 12 '24 03:01 basicdays