Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django-stubs/db/models/query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class QuerySet(AltersData, _SupportsContains[object], Iterable[_Row_co], Sized,
def __getitem__(self, i: int) -> _Row_co: ...
@overload
def __getitem__(self, s: slice) -> Self: ...
def __class_getitem__(cls, item: type[_Model_co]) -> Self: ...
def __class_getitem__(cls, *args: Any, **kwargs: Any) -> type[Self]: ...
# Technically, the other QuerySet must be of the same type _T_co, but _T_co is covariant
def __and__(self, other: QuerySet[_Model_co, _Row_co]) -> Self: ...
def __or__(self, other: QuerySet[_Model_co, _Row_co]) -> Self: ...
Expand Down
6 changes: 5 additions & 1 deletion tests/assert_type/db/models/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from typing import TYPE_CHECKING, assert_type

from django.db.models import Model
from django.db.models.query import QuerySet, RawQuerySet, aprefetch_related_objects, prefetch_related_objects

if TYPE_CHECKING:
from collections.abc import Sequence

from django.contrib.auth.models import AnonymousUser
from django.db.models import Model

models_list: list[Model] = []
prefetch_related_objects(models_list, "pk")
Expand Down Expand Up @@ -51,3 +51,7 @@ def test_in_operator(
assert_type(None in qs, bool)
assert_type("test" in qs, bool)
assert_type(42 in qs, bool)


def test_class_getitem_returns_the_class(qs_class: type[QuerySet[Model]]) -> None:
assert_type(qs_class.__class_getitem__(Model), type[QuerySet[Model]])
Loading