Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions githubkit/rest/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@


class PaginatorState(TypedDict):
response: Response[Any]
next_link: Optional[httpx.URL]
request_method: str
response_model: Any
Expand Down Expand Up @@ -89,6 +90,11 @@ def __init__(
self._index: int = 0
self._cached_data: list[RT] = []

@property
def latest_response(self) -> Optional[Response[Any]]:
"""The latest API response of the paginator."""
return self._state["response"] if self._state is not None else None

@property
def finalized(self) -> bool:
"""Whether the paginator is finalized or not."""
Expand Down Expand Up @@ -180,6 +186,7 @@ def _get_next_page(self) -> None:
)

self._state = PaginatorState(
response=response,
next_link=self._find_next_link(response),
request_method=response.raw_request.method,
response_model=response._data_model,
Expand Down Expand Up @@ -209,6 +216,7 @@ async def _aget_next_page(self) -> None:
)

self._state = PaginatorState(
response=response,
next_link=self._find_next_link(response),
request_method=response.raw_request.method,
response_model=response._data_model,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_rest/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_paginate(g: GitHub):
)
count = 0
for issue in paginator:
assert paginator.latest_response is not None
assert isinstance(issue, Issue)
if not issue.pull_request:
count += 1
Expand Down Expand Up @@ -124,6 +125,7 @@ async def test_async_paginate(g: GitHub):
)
count = 0
async for issue in paginator:
assert paginator.latest_response is not None
assert isinstance(issue, Issue)
if not issue.pull_request:
count += 1
Expand Down
Loading