Skip to content

Commit f3d9703

Browse files
authored
Expect a QuerySet for multiple defaults in MultipleObjectMixin (#2191)
When `MultipleObjectMixin` adds a more specific type than "something that can be sliced" (i.e. `_SupportsPagination`) for default types of queryset attributes/arguments a couple of subclass views gets a better default behaviour.
1 parent 8703696 commit f3d9703

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

django-stubs/views/generic/list.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ from collections.abc import Sequence
22
from typing import Any, Generic, TypeVar
33

44
from django.core.paginator import Page, Paginator, _SupportsPagination
5-
from django.db.models import Model
5+
from django.db.models import Model, QuerySet
66
from django.http import HttpRequest, HttpResponse
77
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
88

99
_M = TypeVar("_M", bound=Model, covariant=True)
1010

1111
class MultipleObjectMixin(Generic[_M], ContextMixin):
1212
allow_empty: bool
13-
queryset: _SupportsPagination[_M] | None
13+
queryset: QuerySet[_M] | None
1414
model: type[_M] | None
1515
paginate_by: int | None
1616
paginate_orphans: int
1717
context_object_name: str | None
1818
paginator_class: type[Paginator]
1919
page_kwarg: str
2020
ordering: str | Sequence[str] | None
21-
def get_queryset(self) -> _SupportsPagination[_M]: ...
21+
def get_queryset(self) -> QuerySet[_M]: ...
2222
def get_ordering(self) -> str | Sequence[str] | None: ...
2323
def paginate_queryset(
2424
self, queryset: _SupportsPagination[_M], page_size: int
2525
) -> tuple[Paginator, Page, _SupportsPagination[_M], bool]: ...
26-
def get_paginate_by(self, queryset: _SupportsPagination[_M]) -> int | None: ...
26+
def get_paginate_by(self, queryset: QuerySet[_M]) -> int | None: ...
2727
def get_paginator(
2828
self,
2929
queryset: _SupportsPagination[_M],

tests/typecheck/views/generic/test_list.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@
4848
...
4949
out: |
5050
main:7: error: Incompatible types in assignment (expression has type "Type[MyModel]", base class "MultipleObjectMixin" defined the type as "Optional[Type[Other]]") [assignment]
51-
main:8: error: Incompatible types in assignment (expression has type "QuerySet[MyModel, MyModel]", base class "MultipleObjectMixin" defined the type as "Optional[_SupportsPagination[Other]]") [assignment]
52-
main:10: error: Return type "QuerySet[MyModel, MyModel]" of "get_queryset" incompatible with return type "_SupportsPagination[Other]" in supertype "MultipleObjectMixin" [override]
51+
main:8: error: Incompatible types in assignment (expression has type "QuerySet[MyModel, MyModel]", base class "MultipleObjectMixin" defined the type as "Optional[QuerySet[Other, Other]]") [assignment]
52+
main:10: error: Return type "QuerySet[MyModel, MyModel]" of "get_queryset" incompatible with return type "QuerySet[Other, Other]" in supertype "MultipleObjectMixin" [override]

0 commit comments

Comments
 (0)