Skip to content

Commit 9adf490

Browse files
feat(pagination): remove unused types (#215)
1 parent cd5253c commit 9adf490

File tree

1 file changed

+70
-38
lines changed

1 file changed

+70
-38
lines changed

src/finch/pagination.py

+70-38
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class SyncSinglePage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
3030

3131
@override
3232
def _get_page_items(self) -> List[ModelT]:
33-
return self.items
33+
items = self.items
34+
if not items:
35+
return []
36+
return items
3437

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

5659
@override
5760
def _get_page_items(self) -> List[ModelT]:
58-
return self.items
61+
items = self.items
62+
if not items:
63+
return []
64+
return items
5965

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

8187
@override
8288
def _get_page_items(self) -> List[ModelT]:
83-
return self.responses
89+
responses = self.responses
90+
if not responses:
91+
return []
92+
return responses
8493

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

97106
@override
98107
def _get_page_items(self) -> List[ModelT]:
99-
return self.responses
108+
responses = self.responses
109+
if not responses:
110+
return []
111+
return responses
100112

101113
@override
102114
def next_page_info(self) -> None:
@@ -107,32 +119,35 @@ def next_page_info(self) -> None:
107119
return None
108120

109121

110-
IndividualsPagePaging = Paging
111-
"""This is deprecated, Paging should be used instead"""
112-
113-
114122
class SyncIndividualsPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
115123
individuals: List[ModelT]
116124
paging: Paging
117125

118126
@override
119127
def _get_page_items(self) -> List[ModelT]:
120-
return self.individuals
128+
individuals = self.individuals
129+
if not individuals:
130+
return []
131+
return individuals
121132

122133
@override
123134
def next_page_info(self) -> Optional[PageInfo]:
124-
offset = self.paging.offset
135+
offset = None
136+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
137+
offset = self.paging.offset
125138
if offset is None:
126139
return None
127140

128-
length = len(self.individuals)
141+
length = len(self._get_page_items())
129142
current_count = offset + length
130143

131-
total_count = self.paging.count
132-
if total_count is None:
144+
count = None
145+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
146+
count = self.paging.count
147+
if count is None:
133148
return None
134149

135-
if current_count < total_count:
150+
if current_count < count:
136151
return PageInfo(params={"offset": current_count})
137152

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

145160
@override
146161
def _get_page_items(self) -> List[ModelT]:
147-
return self.individuals
162+
individuals = self.individuals
163+
if not individuals:
164+
return []
165+
return individuals
148166

149167
@override
150168
def next_page_info(self) -> Optional[PageInfo]:
151-
offset = self.paging.offset
169+
offset = None
170+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
171+
offset = self.paging.offset
152172
if offset is None:
153173
return None
154174

155-
length = len(self.individuals)
175+
length = len(self._get_page_items())
156176
current_count = offset + length
157177

158-
total_count = self.paging.count
159-
if total_count is None:
178+
count = None
179+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
180+
count = self.paging.count
181+
if count is None:
160182
return None
161183

162-
if current_count < total_count:
184+
if current_count < count:
163185
return PageInfo(params={"offset": current_count})
164186

165187
return None
166188

167189

168-
PagePaging = Paging
169-
"""This is deprecated, Paging should be used instead"""
170-
171-
172190
class SyncPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
173-
paging: Paging
174191
data: List[ModelT]
192+
paging: Paging
175193

176194
@override
177195
def _get_page_items(self) -> List[ModelT]:
178-
return self.data
196+
data = self.data
197+
if not data:
198+
return []
199+
return data
179200

180201
@override
181202
def next_page_info(self) -> Optional[PageInfo]:
182-
offset = self.paging.offset
203+
offset = None
204+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
205+
offset = self.paging.offset
183206
if offset is None:
184207
return None
185208

186-
length = len(self.data)
209+
length = len(self._get_page_items())
187210
current_count = offset + length
188211

189-
total_count = self.paging.count
190-
if total_count is None:
212+
count = None
213+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
214+
count = self.paging.count
215+
if count is None:
191216
return None
192217

193-
if current_count < total_count:
218+
if current_count < count:
194219
return PageInfo(params={"offset": current_count})
195220

196221
return None
197222

198223

199224
class AsyncPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
200-
paging: Paging
201225
data: List[ModelT]
226+
paging: Paging
202227

203228
@override
204229
def _get_page_items(self) -> List[ModelT]:
205-
return self.data
230+
data = self.data
231+
if not data:
232+
return []
233+
return data
206234

207235
@override
208236
def next_page_info(self) -> Optional[PageInfo]:
209-
offset = self.paging.offset
237+
offset = None
238+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
239+
offset = self.paging.offset
210240
if offset is None:
211241
return None
212242

213-
length = len(self.data)
243+
length = len(self._get_page_items())
214244
current_count = offset + length
215245

216-
total_count = self.paging.count
217-
if total_count is None:
246+
count = None
247+
if self.paging is not None: # pyright: ignore[reportUnnecessaryComparison]
248+
count = self.paging.count
249+
if count is None:
218250
return None
219251

220-
if current_count < total_count:
252+
if current_count < count:
221253
return PageInfo(params={"offset": current_count})
222254

223255
return None

0 commit comments

Comments
 (0)