Skip to content

Commit cc341f4

Browse files
chore(internal): minor updates to pagination (#91)
1 parent ce98611 commit cc341f4

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

src/orb/pagination.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ._models import BaseModel
88
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
99

10-
__all__ = ["SyncPage", "AsyncPage"]
10+
__all__ = ["PagePaginationMetadata", "SyncPage", "AsyncPage"]
1111

1212

1313
class PagePaginationMetadata(BaseModel):
@@ -22,15 +22,20 @@ class SyncPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
2222

2323
@override
2424
def _get_page_items(self) -> List[ModelT]:
25-
return self.data
25+
data = self.data
26+
if not data:
27+
return []
28+
return data
2629

2730
@override
2831
def next_page_info(self) -> Optional[PageInfo]:
29-
cursor = self.pagination_metadata.next_cursor
30-
if not cursor:
32+
next_cursor = None
33+
if self.pagination_metadata is not None: # pyright: ignore[reportUnnecessaryComparison]
34+
next_cursor = self.pagination_metadata.next_cursor
35+
if not next_cursor:
3136
return None
3237

33-
return PageInfo(params={"cursor": cursor})
38+
return PageInfo(params={"cursor": next_cursor})
3439

3540

3641
class AsyncPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
@@ -39,12 +44,17 @@ class AsyncPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
3944

4045
@override
4146
def _get_page_items(self) -> List[ModelT]:
42-
return self.data
47+
data = self.data
48+
if not data:
49+
return []
50+
return data
4351

4452
@override
4553
def next_page_info(self) -> Optional[PageInfo]:
46-
cursor = self.pagination_metadata.next_cursor
47-
if not cursor:
54+
next_cursor = None
55+
if self.pagination_metadata is not None: # pyright: ignore[reportUnnecessaryComparison]
56+
next_cursor = self.pagination_metadata.next_cursor
57+
if not next_cursor:
4858
return None
4959

50-
return PageInfo(params={"cursor": cursor})
60+
return PageInfo(params={"cursor": next_cursor})

tests/api_resources/test_customers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import pytest
88

99
from orb import Orb, AsyncOrb
10-
from orb.types import Customer
10+
from orb.types import (
11+
Customer,
12+
)
1113
from orb._utils import parse_datetime
1214
from orb._client import Orb, AsyncOrb
1315
from tests.utils import assert_matches_type

tests/api_resources/test_invoices.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import pytest
88

99
from orb import Orb, AsyncOrb
10-
from orb.types import Invoice, InvoiceFetchUpcomingResponse
10+
from orb.types import (
11+
Invoice,
12+
InvoiceFetchUpcomingResponse,
13+
)
1114
from orb._utils import parse_date, parse_datetime
1215
from orb._client import Orb, AsyncOrb
1316
from tests.utils import assert_matches_type

tests/api_resources/test_metrics.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import pytest
88

99
from orb import Orb, AsyncOrb
10-
from orb.types import MetricListResponse, MetricFetchResponse, MetricCreateResponse
10+
from orb.types import (
11+
MetricListResponse,
12+
MetricFetchResponse,
13+
MetricCreateResponse,
14+
)
1115
from orb._utils import parse_datetime
1216
from orb._client import Orb, AsyncOrb
1317
from tests.utils import assert_matches_type

0 commit comments

Comments
 (0)