Skip to content

Commit

Permalink
Expect a QuerySet for multiple defaults in MultipleObjectMixin (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
flaeppe authored Jun 28, 2024
1 parent 8703696 commit f3d9703
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions django-stubs/views/generic/list.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ from collections.abc import Sequence
from typing import Any, Generic, TypeVar

from django.core.paginator import Page, Paginator, _SupportsPagination
from django.db.models import Model
from django.db.models import Model, QuerySet
from django.http import HttpRequest, HttpResponse
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View

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

class MultipleObjectMixin(Generic[_M], ContextMixin):
allow_empty: bool
queryset: _SupportsPagination[_M] | None
queryset: QuerySet[_M] | None
model: type[_M] | None
paginate_by: int | None
paginate_orphans: int
context_object_name: str | None
paginator_class: type[Paginator]
page_kwarg: str
ordering: str | Sequence[str] | None
def get_queryset(self) -> _SupportsPagination[_M]: ...
def get_queryset(self) -> QuerySet[_M]: ...
def get_ordering(self) -> str | Sequence[str] | None: ...
def paginate_queryset(
self, queryset: _SupportsPagination[_M], page_size: int
) -> tuple[Paginator, Page, _SupportsPagination[_M], bool]: ...
def get_paginate_by(self, queryset: _SupportsPagination[_M]) -> int | None: ...
def get_paginate_by(self, queryset: QuerySet[_M]) -> int | None: ...
def get_paginator(
self,
queryset: _SupportsPagination[_M],
Expand Down
4 changes: 2 additions & 2 deletions tests/typecheck/views/generic/test_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
...
out: |
main:7: error: Incompatible types in assignment (expression has type "Type[MyModel]", base class "MultipleObjectMixin" defined the type as "Optional[Type[Other]]") [assignment]
main:8: error: Incompatible types in assignment (expression has type "QuerySet[MyModel, MyModel]", base class "MultipleObjectMixin" defined the type as "Optional[_SupportsPagination[Other]]") [assignment]
main:10: error: Return type "QuerySet[MyModel, MyModel]" of "get_queryset" incompatible with return type "_SupportsPagination[Other]" in supertype "MultipleObjectMixin" [override]
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]
main:10: error: Return type "QuerySet[MyModel, MyModel]" of "get_queryset" incompatible with return type "QuerySet[Other, Other]" in supertype "MultipleObjectMixin" [override]

0 comments on commit f3d9703

Please sign in to comment.