Skip to content

Commit

Permalink
refactor: Mark pagination classes with @override decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Aug 9, 2024
1 parent e0efe9c commit bd4e420
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions singer_sdk/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

from __future__ import annotations

import sys
import typing as t
from abc import ABCMeta, abstractmethod
from urllib.parse import ParseResult, urlparse

from singer_sdk.helpers.jsonpath import extract_jsonpath

if sys.version_info < (3, 12):
from typing_extensions import override
else:
from typing import override # noqa: ICN003

if t.TYPE_CHECKING:
from requests import Response
import requests


T = t.TypeVar("T")
TPageToken = t.TypeVar("TPageToken")
Expand Down Expand Up @@ -87,7 +94,7 @@ def __repr__(self) -> str:
"""
return str(self)

def advance(self, response: Response) -> None:
def advance(self, response: requests.Response) -> None:
"""Get a new page value and advance the current one.
Args:
Expand Down Expand Up @@ -118,7 +125,7 @@ def advance(self, response: Response) -> None:
else:
self._value = new_value

def has_more(self, response: Response) -> bool: # noqa: ARG002, PLR6301
def has_more(self, response: requests.Response) -> bool: # noqa: ARG002, PLR6301
"""Override this method to check if the endpoint has any pages left.
Args:
Expand All @@ -130,7 +137,7 @@ def has_more(self, response: Response) -> bool: # noqa: ARG002, PLR6301
return True

@abstractmethod
def get_next(self, response: Response) -> TPageToken | None:
def get_next(self, response: requests.Response) -> TPageToken | None:
"""Get the next pagination token or index from the API response.
Args:
Expand All @@ -155,15 +162,12 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
"""
super().__init__(None, *args, **kwargs)

def get_next(self, response: Response) -> None: # noqa: ARG002, PLR6301
"""Get the next pagination token or index from the API response.
@override
def get_next(self, response: requests.Response) -> None:
"""Always return None to indicate pagination is complete after the first page.
Args:
response: API response object.
Returns:
The next page token or index. Return `None` from this method to indicate
the end of pagination.
"""
return

Expand Down Expand Up @@ -220,15 +224,16 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
super().__init__(None, *args, **kwargs)

@abstractmethod
def get_next_url(self, response: Response) -> str | None:
def get_next_url(self, response: requests.Response) -> str | None:
"""Override this method to extract a HATEOAS link from the response.
Args:
response: API response object.
"""
...

def get_next(self, response: Response) -> ParseResult | None:
@override
def get_next(self, response: requests.Response) -> ParseResult | None:
"""Get the next pagination token or index from the API response.
Args:
Expand All @@ -249,7 +254,8 @@ class HeaderLinkPaginator(BaseHATEOASPaginator):
- https://datatracker.ietf.org/doc/html/rfc8288#section-3
"""

def get_next_url(self, response: Response) -> str | None: # noqa: PLR6301
@override
def get_next_url(self, response: requests.Response) -> str | None:
"""Override this method to extract a HATEOAS link from the response.
Args:
Expand Down Expand Up @@ -281,7 +287,8 @@ def __init__(
super().__init__(None, *args, **kwargs)
self._jsonpath = jsonpath

def get_next(self, response: Response) -> str | None:
@override
def get_next(self, response: requests.Response) -> str | None:
"""Get the next page token.
Args:
Expand Down Expand Up @@ -313,7 +320,8 @@ def __init__(
super().__init__(None, *args, **kwargs)
self._key = key

def get_next(self, response: Response) -> str | None:
@override
def get_next(self, response: requests.Response) -> str | None:
"""Get the next page token.
Args:
Expand All @@ -328,7 +336,8 @@ def get_next(self, response: Response) -> str | None:
class BasePageNumberPaginator(BaseAPIPaginator[int], metaclass=ABCMeta):
"""Paginator class for APIs that use page number."""

def get_next(self, response: Response) -> int | None: # noqa: ARG002
@override
def get_next(self, response: requests.Response) -> int | None:
"""Get the next page number.
Args:
Expand Down Expand Up @@ -361,7 +370,8 @@ def __init__(
super().__init__(start_value, *args, **kwargs)
self._page_size = page_size

def get_next(self, response: Response) -> int | None: # noqa: ARG002
@override
def get_next(self, response: requests.Response) -> int | None:
"""Get the next page offset.
Args:
Expand All @@ -378,7 +388,7 @@ class LegacyPaginatedStreamProtocol(t.Protocol[TPageToken]):

def get_next_page_token(
self,
response: Response,
response: requests.Response,
previous_token: TPageToken | None,
) -> TPageToken | None:
"""Get the next page token.
Expand Down Expand Up @@ -411,7 +421,8 @@ def __init__(
super().__init__(None, *args, **kwargs)
self.stream = stream

def get_next(self, response: Response) -> TPageToken | None:
@override
def get_next(self, response: requests.Response) -> TPageToken | None:
"""Get next page value by calling the stream method.
Args:
Expand Down

0 comments on commit bd4e420

Please sign in to comment.