Commit e2f2db8a

stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
2025-02-06 23:16:44
feat(pagination): avoid fetching when has_more: false (#2098)
1 parent af6a943
Changed files (2)
src/openai/pagination.py
@@ -61,6 +61,7 @@ class AsyncPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
 
 class SyncCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
     data: List[_T]
+    has_more: Optional[bool] = None
 
     @override
     def _get_page_items(self) -> List[_T]:
@@ -69,6 +70,14 @@ class SyncCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
             return []
         return data
 
+    @override
+    def has_next_page(self) -> bool:
+        has_more = self.has_more
+        if has_more is not None and has_more is False:
+            return False
+
+        return super().has_next_page()
+
     @override
     def next_page_info(self) -> Optional[PageInfo]:
         data = self.data
@@ -85,6 +94,7 @@ class SyncCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
 
 class AsyncCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
     data: List[_T]
+    has_more: Optional[bool] = None
 
     @override
     def _get_page_items(self) -> List[_T]:
@@ -93,6 +103,14 @@ class AsyncCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
             return []
         return data
 
+    @override
+    def has_next_page(self) -> bool:
+        has_more = self.has_more
+        if has_more is not None and has_more is False:
+            return False
+
+        return super().has_next_page()
+
     @override
     def next_page_info(self) -> Optional[PageInfo]:
         data = self.data
.stats.yml
@@ -1,2 +1,2 @@
 configured_endpoints: 69
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-7c699d4503077d06a4a44f52c0c1f902d19a87c766b8be75b97c8dfd484ad4aa.yml
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-dfb00c627f58e5180af7a9b29ed2f2aa0764a3b9daa6a32a1cc45bc8e48dfe15.yml