11# Size of a single page in a paginated query.
22from abc import ABC , abstractmethod
3- from labelbox .orm .db_object import DbObject
4- from typing import Any , Dict , List , Optional
5- from labelbox import Client
3+ from typing import Any , Callable , Dict , List , Optional
4+
5+ from typing import TYPE_CHECKING
6+ if TYPE_CHECKING :
7+ from labelbox import Client
8+ from labelbox .orm .db_object import DbObject
69
710_PAGE_SIZE = 100
811
@@ -17,11 +20,11 @@ class PaginatedCollection:
1720 """
1821
1922 def __init__ (self ,
20- client : Client ,
23+ client : " Client" ,
2124 query : str ,
2225 params : Dict [str , str ],
2326 dereferencing : Dict [str , Any ],
24- obj_class : DbObject ,
27+ obj_class : " DbObject" ,
2528 cursor_path : Optional [Dict [str , Any ]] = None ,
2629 beta : bool = False ):
2730 """ Creates a PaginatedCollection.
@@ -45,12 +48,14 @@ def __init__(self,
4548 self .params = params
4649 self .dereferencing = dereferencing
4750 self .obj_class = obj_class
51+ self .cursor_path = cursor_path
4852 self .beta = beta
4953
5054 self ._fetched_all = False
5155 self ._data : List [Dict [str , Any ]] = []
5256 self ._data_ind = 0
53- self .cursor_path = _CursorPagination (
57+
58+ self .paginator = _CursorPagination (
5459 client , cursor_path ) if cursor_path else _OffsetPagination (client )
5560
5661 def __iter__ (self ):
@@ -97,7 +102,7 @@ def fetch_results(self, query: str, params: Dict[str, Any],
97102
98103class _CursorPagination (_Pagination ):
99104
100- def __init__ (self , client : Client , cursor_path : Dict [str , Any ]):
105+ def __init__ (self , client : " Client" , cursor_path : Dict [str , Any ]):
101106 self .client = client
102107 self .cursor_path = cursor_path
103108 self .next_cursor : Optional [str ] = None
@@ -119,7 +124,7 @@ def fetch_results(self, query: str, params: Dict[str, Any],
119124
120125class _OffsetPagination (_Pagination ):
121126
122- def __init__ (self , client ):
127+ def __init__ (self , client : "Client" ):
123128 self .client = client
124129 self ._fetched_pages = 0
125130
0 commit comments