8

I am doing Django development using visual studio code on mac os with microsoft's pylance extension installed. Following is the version specification of my eco system :

OS -> MacOS Mojave
django -> 3.1.5
visual studio code -> 1.52.1
Microsoft Pylance -> 2021.1.2 Release (latest) 

We use JSONField from django's 3.1.5 version. Pylance use stub files for django located at extensions/ms-python.vscode-pylance-2021.1.2/dist/bundled/stubs/djano/db/models/__init__.pyi

enter image description here

I can clearly see that stubs file mentioned is not up-to-date. Because of that, vscode is not able to resolve reference to models.JSONField. While for other libraries like jsonschema , it simply relies on their __init__.py. That's what I want.

enter image description here

I checked what all can be configured on official page of Pylance but I did not find any suitable configuraiton. https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance

I am considering following options :

  1. Delete stubs file/directory for django, I don't know what will be repercussions.
  2. Manually setting python.analysis.extraPaths to my virtualenv path.

I am looking for a more organic solution and I'll provide the result of the above experiments in the comments.

Thanks !

Gama11
  • 31,714
  • 9
  • 78
  • 100
Utsav Chokshi
  • 1,357
  • 1
  • 13
  • 35
  • 4
    Option 1 works. I have deleted django from `~/.vscode/extensions/ms-python.vscode-pylance-2021.1.2/dist/bundled/stubs/django` and it started paying respect to django it deserves ! :) – Utsav Chokshi Jan 22 '21 at 19:29
  • 1
    since you have a workaround, `I suggest you could add it as answer rather than a comment, and then mark your own answer.` I could help other community members search and handle similar issues:) Thanks in advanced! – Mr Qian Jan 25 '21 at 07:48
  • related https://stackoverflow.com/questions/64701174/pylance-does-not-allow-me-to-navigate-to-the-source-code-bringing-me-to-the-py/71806760#71806760 – ohkts11 Apr 09 '22 at 09:25
  • 1
    @UtsavChokshi didn't work for me. The "Go to Definition" feature just stopped working altogether :( – Ariel Jan 26 '23 at 11:04

0 Answers0