Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect a QuerySet for multiple defaults in MultipleObjectMixin #2191

Merged
merged 2 commits into from
Jun 28, 2024
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
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]
Loading