Skip to content

Commit c108714

Browse files
authored
✨ Feature: add latest response to paginator state (#269)
1 parent 58460fd commit c108714

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

githubkit/rest/paginator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939

4040
class PaginatorState(TypedDict):
41+
response: Response[Any]
4142
next_link: Optional[httpx.URL]
4243
request_method: str
4344
response_model: Any
@@ -89,6 +90,11 @@ def __init__(
8990
self._index: int = 0
9091
self._cached_data: list[RT] = []
9192

93+
@property
94+
def latest_response(self) -> Optional[Response[Any]]:
95+
"""The latest API response of the paginator."""
96+
return self._state["response"] if self._state is not None else None
97+
9298
@property
9399
def finalized(self) -> bool:
94100
"""Whether the paginator is finalized or not."""
@@ -180,6 +186,7 @@ def _get_next_page(self) -> None:
180186
)
181187

182188
self._state = PaginatorState(
189+
response=response,
183190
next_link=self._find_next_link(response),
184191
request_method=response.raw_request.method,
185192
response_model=response._data_model,
@@ -209,6 +216,7 @@ async def _aget_next_page(self) -> None:
209216
)
210217

211218
self._state = PaginatorState(
219+
response=response,
212220
next_link=self._find_next_link(response),
213221
request_method=response.raw_request.method,
214222
response_model=response._data_model,

tests/test_rest/test_call.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_paginate(g: GitHub):
9797
)
9898
count = 0
9999
for issue in paginator:
100+
assert paginator.latest_response is not None
100101
assert isinstance(issue, Issue)
101102
if not issue.pull_request:
102103
count += 1
@@ -124,6 +125,7 @@ async def test_async_paginate(g: GitHub):
124125
)
125126
count = 0
126127
async for issue in paginator:
128+
assert paginator.latest_response is not None
127129
assert isinstance(issue, Issue)
128130
if not issue.pull_request:
129131
count += 1

0 commit comments

Comments
 (0)