The Django stubs that ship with the Pylance VSCode extension are out of date, and take precedence over stubs installed in the local environment.
Environment data
- Language Server version: 2024.6.1
- OS and version: MacOS Sonoma 14.5
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.2
Code Snippet
n/a
Repro Steps
- In a Python 3.12 (virtual) environment:
git clone git@github.com:simonwhitaker/pyright-stubs-demo.git
cd pyright-stubs-demo
pip install -r requirements.txt
- Open the cloned repo in VS Code
- Open
manage.py
- Observe that
RemovedInDjango51Warning on L6 is highlighted
- Observe the error:
"RemovedInDjango51Warning" is unknown import symbol
Expected behavior
RemovedInDjango51Warning is a legitimate symbol in Django 5.0.6, and should not be highlighted. If you command-click (probably ctrl-click on Linux/Windows?) on django.utils.deprecation you will find it defined there.
Actual behavior
See screenshot above.
This appears to be because the django stubs shipped with the Pylance extension are out of date:
$ $ cat ~/.vscode/extensions/ms-python.vscode-pylance-2024.6.1/dist/bundled/stubs/django-stubs/utils/deprecation.pyi
from collections.abc import Callable
from typing import Any
from django.http.request import HttpRequest
from django.http.response import HttpResponse
class RemovedInDjango30Warning(PendingDeprecationWarning): ...
class RemovedInDjango31Warning(PendingDeprecationWarning): ...
class RemovedInDjango40Warning(PendingDeprecationWarning): ...
class RemovedInNextVersionWarning(DeprecationWarning): ...
class warn_about_renamed_method:
class_name: str = ...
old_method_name: str = ...
new_method_name: str = ...
deprecation_warning: type[DeprecationWarning] = ...
def __init__(
self,
class_name: str,
old_method_name: str,
new_method_name: str,
deprecation_warning: type[DeprecationWarning],
) -> None: ...
def __call__(self, f: Callable[..., Any]) -> Callable[..., Any]: ...
class RenameMethodsBase(type):
renamed_methods: Any = ...
def __new__(cls, name: Any, bases: Any, attrs: Any) -> Any: ...
class DeprecationInstanceCheck(type):
alternative: str
deprecation_warning: type[Warning]
def __instancecheck__(self, instance: Any) -> Any: ...
GetResponseCallable = Callable[[HttpRequest], HttpResponse]
class MiddlewareMixin:
get_response: GetResponseCallable | None = ...
def __init__(self, get_response: GetResponseCallable | None = ...) -> None: ...
def __call__(self, request: HttpRequest) -> HttpResponse: ...
Logs
The Django stubs that ship with the Pylance VSCode extension are out of date, and take precedence over stubs installed in the local environment.
Environment data
Code Snippet
n/a
Repro Steps
git clone git@github.com:simonwhitaker/pyright-stubs-demo.git cd pyright-stubs-demo pip install -r requirements.txtmanage.pyRemovedInDjango51Warningon L6 is highlighted"RemovedInDjango51Warning" is unknown import symbolExpected behavior
RemovedInDjango51Warningis a legitimate symbol in Django 5.0.6, and should not be highlighted. If you command-click (probably ctrl-click on Linux/Windows?) ondjango.utils.deprecationyou will find it defined there.Actual behavior
See screenshot above.
This appears to be because the django stubs shipped with the Pylance extension are out of date:
Logs