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

[5.0] Update core.paginator #1946

Merged
merged 2 commits into from
Feb 15, 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
4 changes: 4 additions & 0 deletions django-stubs/core/paginator.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Iterable, Iterator, Sequence, Sized
from typing import ClassVar, Generic, Protocol, TypeVar, overload, type_check_only

from django.db.fields import _ErrorMessagesDict
from django.utils.functional import _StrPromise, cached_property

class UnorderedObjectListWarning(RuntimeWarning): ...
Expand All @@ -19,6 +20,8 @@ class _SupportsPagination(Protocol[_T], Sized, Iterable):

class Paginator(Generic[_T]):
ELLIPSIS: ClassVar[_StrPromise]
default_error_messages: ClassVar[_ErrorMessagesDict]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values are actually guaranteed to be _StrPromise, but I think it's fine to leave it this way (dict[str, _StrOrPromise])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect you'd then run in to troubles if you want to declare your own default_error_messages not bothering about translation strings. e.g.

class X(Paginator):
    default_error_messages = {"key": "not a translated string"}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes right

error_messages: _ErrorMessagesDict
object_list: _SupportsPagination[_T]
per_page: int
orphans: int
Expand All @@ -29,6 +32,7 @@ class Paginator(Generic[_T]):
per_page: int | str,
orphans: int = ...,
allow_empty_first_page: bool = ...,
error_messages: _ErrorMessagesDict | None = ...,
) -> None: ...
def __iter__(self) -> Iterator[Page[_T]]: ...
def validate_number(self, number: int | float | str) -> int: ...
Expand Down
2 changes: 0 additions & 2 deletions scripts/stubtest/allowlist_todo_django50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ django.core.handlers.asgi.ASGIHandler.run_get_response
django.core.handlers.asgi.get_script_prefix
django.core.management.commands.inspectdb.Command.normalize_table_name
django.core.management.commands.optimizemigration
django.core.paginator.Paginator.__init__
django.core.paginator.Paginator.default_error_messages
django.core.serializers.base.PickleSerializer
django.core.validators.StepValueValidator.__init__
django.db.backends.base.base.timezone_constructor
Expand Down