Skip to content

Django stubs are out of date and cause erroneous type errors #6029

Description

@simonwhitaker

The Django stubs that ship with the Pylance VSCode extension are out of date, and take precedence over stubs installed in the local environment.

Screenshot 2024-06-18 at 5 06 14 PM

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

  1. 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
  2. Open the cloned repo in VS Code
  3. Open manage.py
  4. Observe that RemovedInDjango51Warning on L6 is highlighted
  5. 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

XXX

Metadata

Metadata

Assignees

Labels

djangoRelated to django supportrepro workspaceIssue has a retained repro workspace

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions