Skip to content

Commit 1ccd494

Browse files
Add pagination config, fix readme params
1 parent 2a93203 commit 1ccd494

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 9
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nanonets%2Fdocstrange-a418fe45369669cc2d14b549ee010f3a7ee52f6e47fea3489e560d33064be099.yml
33
openapi_spec_hash: 02f7f52faae1eb42188c290c32c25f10
4-
config_hash: 5095aef18b1e8c018bc58e39d6f4b23d
4+
config_hash: 618498b0a12e1535b716981b83e1f760

src/docstrange/pagination.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List, Generic, TypeVar, Optional, cast
4+
from typing_extensions import override
5+
6+
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
7+
8+
__all__ = ["SyncPageNumberPagination", "AsyncPageNumberPagination"]
9+
10+
_T = TypeVar("_T")
11+
12+
13+
class SyncPageNumberPagination(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
14+
items: List[_T]
15+
total_count: Optional[int] = None
16+
has_next: Optional[bool] = None
17+
18+
@override
19+
def _get_page_items(self) -> List[_T]:
20+
items = self.items
21+
if not items:
22+
return []
23+
return items
24+
25+
@override
26+
def next_page_info(self) -> Optional[PageInfo]:
27+
last_page = cast("int | None", self._options.params.get("page")) or 1
28+
29+
return PageInfo(params={"page": last_page + 1})
30+
31+
32+
class AsyncPageNumberPagination(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
33+
items: List[_T]
34+
total_count: Optional[int] = None
35+
has_next: Optional[bool] = None
36+
37+
@override
38+
def _get_page_items(self) -> List[_T]:
39+
items = self.items
40+
if not items:
41+
return []
42+
return items
43+
44+
@override
45+
def next_page_info(self) -> Optional[PageInfo]:
46+
last_page = cast("int | None", self._options.params.get("page")) or 1
47+
48+
return PageInfo(params={"page": last_page + 1})

0 commit comments

Comments
 (0)