diff --git a/githubkit/rest/paginator.py b/githubkit/rest/paginator.py index d02fbf943..6befc75ee 100644 --- a/githubkit/rest/paginator.py +++ b/githubkit/rest/paginator.py @@ -38,6 +38,7 @@ class PaginatorState(TypedDict): + response: Response[Any] next_link: Optional[httpx.URL] request_method: str response_model: Any @@ -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.""" @@ -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, @@ -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, diff --git a/tests/test_rest/test_call.py b/tests/test_rest/test_call.py index 02a70f4a9..c358a94a0 100644 --- a/tests/test_rest/test_call.py +++ b/tests/test_rest/test_call.py @@ -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 @@ -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