Skip to content

Commit 3f5d18f

Browse files
fix(pagination): don't duplicate shared types (#86)
1 parent 95d0870 commit 3f5d18f

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

src/finch/pagination.py

+21-40
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from httpx import Response
66

7+
from .types import Paging
78
from ._types import ModelT
89
from ._utils import is_mapping
910
from ._models import BaseModel
@@ -101,17 +102,13 @@ def next_page_info(self) -> None:
101102
return None
102103

103104

104-
class IndividualsPagePaging(BaseModel):
105-
count: Optional[int] = None
106-
"""The total number of elements for the entire query (not just the given page)"""
107-
108-
offset: Optional[int] = None
109-
"""The current start index of the returned list of elements"""
105+
IndividualsPagePaging = Paging
106+
"""This is deprecated, Paging should be used instead"""
110107

111108

112109
class SyncIndividualsPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
113-
paging: IndividualsPagePaging
114110
individuals: List[ModelT]
111+
paging: Paging
115112

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

136133

137134
class AsyncIndividualsPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
138-
paging: IndividualsPagePaging
139135
individuals: List[ModelT]
136+
paging: Paging
140137

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

161158

162-
class CandidatesPagePaging(BaseModel):
163-
count: Optional[int] = None
164-
"""The total number of elements for the entire query (not just the given page)"""
165-
166-
offset: Optional[int] = None
167-
"""The current start index of the returned list of elements"""
159+
CandidatesPagePaging = Paging
160+
"""This is deprecated, Paging should be used instead"""
168161

169162

170163
class SyncCandidatesPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
171-
paging: CandidatesPagePaging
172164
candidates: List[ModelT]
165+
paging: Paging
173166

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

194187

195188
class AsyncCandidatesPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
196-
paging: CandidatesPagePaging
197189
candidates: List[ModelT]
190+
paging: Paging
198191

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

219212

220-
class ApplicationsPagePaging(BaseModel):
221-
count: Optional[int] = None
222-
"""The total number of elements for the entire query (not just the given page)"""
223-
224-
offset: Optional[int] = None
225-
"""The current start index of the returned list of elements"""
213+
ApplicationsPagePaging = Paging
214+
"""This is deprecated, Paging should be used instead"""
226215

227216

228217
class SyncApplicationsPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
229-
paging: ApplicationsPagePaging
230218
applications: List[ModelT]
219+
paging: Paging
231220

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

252241

253242
class AsyncApplicationsPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
254-
paging: ApplicationsPagePaging
255243
applications: List[ModelT]
244+
paging: Paging
256245

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

277266

278-
class JobsPagePaging(BaseModel):
279-
count: Optional[int] = None
280-
"""The total number of elements for the entire query (not just the given page)"""
281-
282-
offset: Optional[int] = None
283-
"""The current start index of the returned list of elements"""
267+
JobsPagePaging = Paging
268+
"""This is deprecated, Paging should be used instead"""
284269

285270

286271
class SyncJobsPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
287-
paging: JobsPagePaging
288272
jobs: List[ModelT]
273+
paging: Paging
289274

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

310295

311296
class AsyncJobsPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
312-
paging: JobsPagePaging
313297
jobs: List[ModelT]
298+
paging: Paging
314299

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

335320

336-
class OffersPagePaging(BaseModel):
337-
count: Optional[int] = None
338-
"""The total number of elements for the entire query (not just the given page)"""
339-
340-
offset: Optional[int] = None
341-
"""The current start index of the returned list of elements"""
321+
OffersPagePaging = Paging
322+
"""This is deprecated, Paging should be used instead"""
342323

343324

344325
class SyncOffersPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
345-
paging: OffersPagePaging
346326
offers: List[ModelT]
327+
paging: Paging
347328

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

368349

369350
class AsyncOffersPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
370-
paging: OffersPagePaging
371351
offers: List[ModelT]
352+
paging: Paging
372353

373354
def _get_page_items(self) -> List[ModelT]:
374355
return self.offers

0 commit comments

Comments
 (0)