Skip to content

Commit 9e7f71b

Browse files
refactor: Mark pagination classes with @override decorator (#2597)
1 parent 5fc0f75 commit 9e7f71b

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

singer_sdk/pagination.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
from __future__ import annotations
44

5+
import sys
56
import typing as t
67
from abc import ABCMeta, abstractmethod
78
from urllib.parse import ParseResult, urlparse
89

910
from singer_sdk.helpers.jsonpath import extract_jsonpath
1011

12+
if sys.version_info < (3, 12):
13+
from typing_extensions import override
14+
else:
15+
from typing import override # noqa: ICN003
16+
1117
if t.TYPE_CHECKING:
12-
from requests import Response
18+
import requests
1319

1420
T = t.TypeVar("T")
1521
TPageToken = t.TypeVar("TPageToken")
@@ -87,7 +93,7 @@ def __repr__(self) -> str:
8793
"""
8894
return str(self)
8995

90-
def advance(self, response: Response) -> None:
96+
def advance(self, response: requests.Response) -> None:
9197
"""Get a new page value and advance the current one.
9298
9399
Args:
@@ -118,7 +124,7 @@ def advance(self, response: Response) -> None:
118124
else:
119125
self._value = new_value
120126

121-
def has_more(self, response: Response) -> bool: # noqa: ARG002, PLR6301
127+
def has_more(self, response: requests.Response) -> bool: # noqa: ARG002, PLR6301
122128
"""Override this method to check if the endpoint has any pages left.
123129
124130
Args:
@@ -130,7 +136,7 @@ def has_more(self, response: Response) -> bool: # noqa: ARG002, PLR6301
130136
return True
131137

132138
@abstractmethod
133-
def get_next(self, response: Response) -> TPageToken | None:
139+
def get_next(self, response: requests.Response) -> TPageToken | None:
134140
"""Get the next pagination token or index from the API response.
135141
136142
Args:
@@ -155,15 +161,12 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
155161
"""
156162
super().__init__(None, *args, **kwargs)
157163

158-
def get_next(self, response: Response) -> None: # noqa: ARG002, PLR6301
159-
"""Get the next pagination token or index from the API response.
164+
@override
165+
def get_next(self, response: requests.Response) -> None:
166+
"""Always return None to indicate pagination is complete after the first page.
160167
161168
Args:
162169
response: API response object.
163-
164-
Returns:
165-
The next page token or index. Return `None` from this method to indicate
166-
the end of pagination.
167170
"""
168171
return
169172

@@ -220,15 +223,16 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
220223
super().__init__(None, *args, **kwargs)
221224

222225
@abstractmethod
223-
def get_next_url(self, response: Response) -> str | None:
226+
def get_next_url(self, response: requests.Response) -> str | None:
224227
"""Override this method to extract a HATEOAS link from the response.
225228
226229
Args:
227230
response: API response object.
228231
"""
229232
...
230233

231-
def get_next(self, response: Response) -> ParseResult | None:
234+
@override
235+
def get_next(self, response: requests.Response) -> ParseResult | None:
232236
"""Get the next pagination token or index from the API response.
233237
234238
Args:
@@ -249,7 +253,8 @@ class HeaderLinkPaginator(BaseHATEOASPaginator):
249253
- https://datatracker.ietf.org/doc/html/rfc8288#section-3
250254
"""
251255

252-
def get_next_url(self, response: Response) -> str | None: # noqa: PLR6301
256+
@override
257+
def get_next_url(self, response: requests.Response) -> str | None:
253258
"""Override this method to extract a HATEOAS link from the response.
254259
255260
Args:
@@ -281,7 +286,8 @@ def __init__(
281286
super().__init__(None, *args, **kwargs)
282287
self._jsonpath = jsonpath
283288

284-
def get_next(self, response: Response) -> str | None:
289+
@override
290+
def get_next(self, response: requests.Response) -> str | None:
285291
"""Get the next page token.
286292
287293
Args:
@@ -313,7 +319,8 @@ def __init__(
313319
super().__init__(None, *args, **kwargs)
314320
self._key = key
315321

316-
def get_next(self, response: Response) -> str | None:
322+
@override
323+
def get_next(self, response: requests.Response) -> str | None:
317324
"""Get the next page token.
318325
319326
Args:
@@ -328,7 +335,8 @@ def get_next(self, response: Response) -> str | None:
328335
class BasePageNumberPaginator(BaseAPIPaginator[int], metaclass=ABCMeta):
329336
"""Paginator class for APIs that use page number."""
330337

331-
def get_next(self, response: Response) -> int | None: # noqa: ARG002
338+
@override
339+
def get_next(self, response: requests.Response) -> int | None:
332340
"""Get the next page number.
333341
334342
Args:
@@ -361,7 +369,8 @@ def __init__(
361369
super().__init__(start_value, *args, **kwargs)
362370
self._page_size = page_size
363371

364-
def get_next(self, response: Response) -> int | None: # noqa: ARG002
372+
@override
373+
def get_next(self, response: requests.Response) -> int | None:
365374
"""Get the next page offset.
366375
367376
Args:
@@ -378,7 +387,7 @@ class LegacyPaginatedStreamProtocol(t.Protocol[TPageToken]):
378387

379388
def get_next_page_token(
380389
self,
381-
response: Response,
390+
response: requests.Response,
382391
previous_token: TPageToken | None,
383392
) -> TPageToken | None:
384393
"""Get the next page token.
@@ -411,7 +420,8 @@ def __init__(
411420
super().__init__(None, *args, **kwargs)
412421
self.stream = stream
413422

414-
def get_next(self, response: Response) -> TPageToken | None:
423+
@override
424+
def get_next(self, response: requests.Response) -> TPageToken | None:
415425
"""Get next page value by calling the stream method.
416426
417427
Args:

0 commit comments

Comments
 (0)