Skip to content

fix(pagination): don't duplicate shared types #86

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
merged 1 commit into from
Sep 1, 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
61 changes: 21 additions & 40 deletions src/finch/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from httpx import Response

from .types import Paging
from ._types import ModelT
from ._utils import is_mapping
from ._models import BaseModel
Expand Down Expand Up @@ -101,17 +102,13 @@ def next_page_info(self) -> None:
return None


class IndividualsPagePaging(BaseModel):
count: Optional[int] = None
"""The total number of elements for the entire query (not just the given page)"""

offset: Optional[int] = None
"""The current start index of the returned list of elements"""
IndividualsPagePaging = Paging
"""This is deprecated, Paging should be used instead"""


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

def _get_page_items(self) -> List[ModelT]:
return self.individuals
Expand All @@ -135,8 +132,8 @@ def next_page_info(self) -> Optional[PageInfo]:


class AsyncIndividualsPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: IndividualsPagePaging
individuals: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.individuals
Expand All @@ -159,17 +156,13 @@ def next_page_info(self) -> Optional[PageInfo]:
return None


class CandidatesPagePaging(BaseModel):
count: Optional[int] = None
"""The total number of elements for the entire query (not just the given page)"""

offset: Optional[int] = None
"""The current start index of the returned list of elements"""
CandidatesPagePaging = Paging
"""This is deprecated, Paging should be used instead"""


class SyncCandidatesPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: CandidatesPagePaging
candidates: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.candidates
Expand All @@ -193,8 +186,8 @@ def next_page_info(self) -> Optional[PageInfo]:


class AsyncCandidatesPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: CandidatesPagePaging
candidates: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.candidates
Expand All @@ -217,17 +210,13 @@ def next_page_info(self) -> Optional[PageInfo]:
return None


class ApplicationsPagePaging(BaseModel):
count: Optional[int] = None
"""The total number of elements for the entire query (not just the given page)"""

offset: Optional[int] = None
"""The current start index of the returned list of elements"""
ApplicationsPagePaging = Paging
"""This is deprecated, Paging should be used instead"""


class SyncApplicationsPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: ApplicationsPagePaging
applications: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.applications
Expand All @@ -251,8 +240,8 @@ def next_page_info(self) -> Optional[PageInfo]:


class AsyncApplicationsPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: ApplicationsPagePaging
applications: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.applications
Expand All @@ -275,17 +264,13 @@ def next_page_info(self) -> Optional[PageInfo]:
return None


class JobsPagePaging(BaseModel):
count: Optional[int] = None
"""The total number of elements for the entire query (not just the given page)"""

offset: Optional[int] = None
"""The current start index of the returned list of elements"""
JobsPagePaging = Paging
"""This is deprecated, Paging should be used instead"""


class SyncJobsPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: JobsPagePaging
jobs: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.jobs
Expand All @@ -309,8 +294,8 @@ def next_page_info(self) -> Optional[PageInfo]:


class AsyncJobsPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: JobsPagePaging
jobs: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.jobs
Expand All @@ -333,17 +318,13 @@ def next_page_info(self) -> Optional[PageInfo]:
return None


class OffersPagePaging(BaseModel):
count: Optional[int] = None
"""The total number of elements for the entire query (not just the given page)"""

offset: Optional[int] = None
"""The current start index of the returned list of elements"""
OffersPagePaging = Paging
"""This is deprecated, Paging should be used instead"""


class SyncOffersPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: OffersPagePaging
offers: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.offers
Expand All @@ -367,8 +348,8 @@ def next_page_info(self) -> Optional[PageInfo]:


class AsyncOffersPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
paging: OffersPagePaging
offers: List[ModelT]
paging: Paging

def _get_page_items(self) -> List[ModelT]:
return self.offers
Expand Down