Skip to content

Fix PageNumberPagination.paginate_queryset() return type #165

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

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
4 changes: 2 additions & 2 deletions rest_framework-stubs/pagination.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class PageNumberPagination(BasePagination):
request: Optional[Request] = ...
template: str = ...
def paginate_queryset(
self, queryset: QuerySet, request: Request, view: Optional[APIView] = ...
) -> Optional[List[Page]]: ...
self, queryset: QuerySet[_MT], request: Request, view: Optional[APIView] = ...
) -> Optional[List[_MT]]: ...
def get_paginated_response_schema(self, schema: Dict[str, Any]) -> Dict[str, Any]: ...
def get_schema_fields(self, view: APIView) -> List[CoreAPIField]: ...
def get_schema_operation_parameters(self, view: APIView) -> List[Dict[str, Any]]: ...
Expand Down
1 change: 1 addition & 0 deletions scripts/typecheck_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
'"MultipleChoiceField[Model]" has no attribute "partial"',
'Argument 1 to "to_internal_value" of "Field" has incompatible type "Dict[str, str]"; expected "List[Any]"',
'Module "rest_framework.fields" has no attribute "DjangoImageField"; maybe "ImageField"?',
'Argument 1 to "ListField" has incompatible type "CharField"; expected "bool"',
],
"test_filters.py": [
'Module has no attribute "coreapi"',
Expand Down
12 changes: 12 additions & 0 deletions tests/typecheck/test_pagination.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- case: test_page_number_pagination_paginate_queryset
main: |
from rest_framework.pagination import PageNumberPagination
from rest_framework.request import Request
from django.contrib.auth.models import User
from django.db.models import QuerySet

paginator = PageNumberPagination()
request: Request
queryset: QuerySet[User]
page = paginator.paginate_queryset(queryset, request)
reveal_type(page) # N: Revealed type is "Union[builtins.list[django.contrib.auth.models.User*], None]"