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

feat(pagination): remove unused types #215

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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
108 changes: 70 additions & 38 deletions src/finch/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class SyncSinglePage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):

@override
def _get_page_items(self) -> List[ModelT]:
return self.items
items = self.items
if not items:
return []
return items

@override
def next_page_info(self) -> None:
Expand All @@ -55,7 +58,10 @@ class AsyncSinglePage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):

@override
def _get_page_items(self) -> List[ModelT]:
return self.items
items = self.items
if not items:
return []
return items

@override
def next_page_info(self) -> None:
Expand All @@ -80,7 +86,10 @@ class SyncResponsesPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT])

@override
def _get_page_items(self) -> List[ModelT]:
return self.responses
responses = self.responses
if not responses:
return []
return responses

@override
def next_page_info(self) -> None:
Expand All @@ -96,7 +105,10 @@ class AsyncResponsesPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT

@override
def _get_page_items(self) -> List[ModelT]:
return self.responses
responses = self.responses
if not responses:
return []
return responses

@override
def next_page_info(self) -> None:
Expand All @@ -107,32 +119,35 @@ def next_page_info(self) -> None:
return None


IndividualsPagePaging = Paging
"""This is deprecated, Paging should be used instead"""


class SyncIndividualsPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
individuals: List[ModelT]
paging: Paging

@override
def _get_page_items(self) -> List[ModelT]:
return self.individuals
individuals = self.individuals
if not individuals:
return []
return individuals

@override
def next_page_info(self) -> Optional[PageInfo]:
offset = self.paging.offset
offset = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
offset = self.paging.offset
if offset is None:
return None

length = len(self.individuals)
length = len(self._get_page_items())
current_count = offset + length

total_count = self.paging.count
if total_count is None:
count = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
count = self.paging.count
if count is None:
return None

if current_count < total_count:
if current_count < count:
return PageInfo(params={"offset": current_count})

return None
Expand All @@ -144,80 +159,97 @@ class AsyncIndividualsPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[Mode

@override
def _get_page_items(self) -> List[ModelT]:
return self.individuals
individuals = self.individuals
if not individuals:
return []
return individuals

@override
def next_page_info(self) -> Optional[PageInfo]:
offset = self.paging.offset
offset = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
offset = self.paging.offset
if offset is None:
return None

length = len(self.individuals)
length = len(self._get_page_items())
current_count = offset + length

total_count = self.paging.count
if total_count is None:
count = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
count = self.paging.count
if count is None:
return None

if current_count < total_count:
if current_count < count:
return PageInfo(params={"offset": current_count})

return None


PagePaging = Paging
"""This is deprecated, Paging should be used instead"""


class SyncPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: Paging
data: List[ModelT]
paging: Paging

@override
def _get_page_items(self) -> List[ModelT]:
return self.data
data = self.data
if not data:
return []
return data

@override
def next_page_info(self) -> Optional[PageInfo]:
offset = self.paging.offset
offset = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
offset = self.paging.offset
if offset is None:
return None

length = len(self.data)
length = len(self._get_page_items())
current_count = offset + length

total_count = self.paging.count
if total_count is None:
count = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
count = self.paging.count
if count is None:
return None

if current_count < total_count:
if current_count < count:
return PageInfo(params={"offset": current_count})

return None


class AsyncPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: Paging
data: List[ModelT]
paging: Paging

@override
def _get_page_items(self) -> List[ModelT]:
return self.data
data = self.data
if not data:
return []
return data

@override
def next_page_info(self) -> Optional[PageInfo]:
offset = self.paging.offset
offset = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
offset = self.paging.offset
if offset is None:
return None

length = len(self.data)
length = len(self._get_page_items())
current_count = offset + length

total_count = self.paging.count
if total_count is None:
count = None
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
count = self.paging.count
if count is None:
return None

if current_count < total_count:
if current_count < count:
return PageInfo(params={"offset": current_count})

return None