Skip to content

Commit

Permalink
Paginator typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Nov 6, 2024
1 parent be61e9d commit 5e4cec8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions django_tables2/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ def set_table(self, table):
@property
def ordering(self):
"""
Returns the list of order by aliases that are enforcing ordering on the
data.
Returns the list of order by aliases that are enforcing ordering on the data.
If the data is unordered, an empty sequence is returned. If the
ordering can not be determined, `None` is returned.
Expand All @@ -185,7 +184,7 @@ def ordering(self):
except StopIteration:
pass

def order_by(self, aliases):
def order_by(self, aliases: OrderByTuple):
"""
Order the data based on order by aliases (prefixed column names) in the
table.
Expand Down
10 changes: 5 additions & 5 deletions django_tables2/paginators.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, object_list, per_page, look_ahead=None, **kwargs):

super().__init__(object_list, per_page, **kwargs)

def validate_number(self, number):
def validate_number(self, number: float | int) -> int:
"""Validate the given 1-based page number."""
try:
if isinstance(number, float) and not number.is_integer():
Expand All @@ -74,7 +74,7 @@ def validate_number(self, number):
raise EmptyPage(_("That page number is less than 1"))
return number

def page(self, number):
def page(self, number: float | int) -> Page:
# Number might be None, because the total number of pages is not known in this paginator.
# If an unknown page is requested, serve the first page.
number = self.validate_number(number or 1)
Expand All @@ -98,20 +98,20 @@ def page(self, number):
self._final_num_pages = number
return Page(objects, number, self)

def is_last_page(self, number):
def is_last_page(self, number: float | int) -> bool:
return number == self._final_num_pages

def _get_count(self):
raise NotImplementedError

count = property(_get_count)

def _get_num_pages(self):
def _get_num_pages(self) -> int:
return self._num_pages

num_pages = property(_get_num_pages)

def _get_page_range(self):
def _get_page_range(self) -> range:
raise NotImplementedError

page_range = property(_get_page_range)

0 comments on commit 5e4cec8

Please sign in to comment.