Skip to content

Commit 03552e7

Browse files
fix(pagination): correct next page check
1 parent 9d9d65e commit 03552e7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/asktable/pagination.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from typing import List, Generic, TypeVar, Optional, cast
3+
from typing import List, Generic, TypeVar, Optional
44
from typing_extensions import override
55

66
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
@@ -29,9 +29,8 @@ def next_page_info(self) -> Optional[PageInfo]:
2929
if current_page is None:
3030
current_page = 1
3131

32-
last_page = cast("int | None", self._options.params.get("page"))
33-
if last_page is not None and current_page <= last_page:
34-
# The API didn't return a new page in the last request
32+
total_pages = self.pages
33+
if total_pages is not None and current_page >= total_pages:
3534
return None
3635

3736
return PageInfo(params={"page": current_page + 1})
@@ -56,9 +55,8 @@ def next_page_info(self) -> Optional[PageInfo]:
5655
if current_page is None:
5756
current_page = 1
5857

59-
last_page = cast("int | None", self._options.params.get("page"))
60-
if last_page is not None and current_page <= last_page:
61-
# The API didn't return a new page in the last request
58+
total_pages = self.pages
59+
if total_pages is not None and current_page >= total_pages:
6260
return None
6361

6462
return PageInfo(params={"page": current_page + 1})

0 commit comments

Comments
 (0)