1
1
# Size of a single page in a paginated query.
2
2
from 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
6
9
7
10
_PAGE_SIZE = 100
8
11
@@ -17,11 +20,11 @@ class PaginatedCollection:
17
20
"""
18
21
19
22
def __init__ (self ,
20
- client : Client ,
23
+ client : " Client" ,
21
24
query : str ,
22
25
params : Dict [str , str ],
23
26
dereferencing : Dict [str , Any ],
24
- obj_class : DbObject ,
27
+ obj_class : " DbObject" ,
25
28
cursor_path : Optional [Dict [str , Any ]] = None ,
26
29
beta : bool = False ):
27
30
""" Creates a PaginatedCollection.
@@ -45,12 +48,14 @@ def __init__(self,
45
48
self .params = params
46
49
self .dereferencing = dereferencing
47
50
self .obj_class = obj_class
51
+ self .cursor_path = cursor_path
48
52
self .beta = beta
49
53
50
54
self ._fetched_all = False
51
55
self ._data : List [Dict [str , Any ]] = []
52
56
self ._data_ind = 0
53
- self .cursor_path = _CursorPagination (
57
+
58
+ self .paginator = _CursorPagination (
54
59
client , cursor_path ) if cursor_path else _OffsetPagination (client )
55
60
56
61
def __iter__ (self ):
@@ -97,7 +102,7 @@ def fetch_results(self, query: str, params: Dict[str, Any],
97
102
98
103
class _CursorPagination (_Pagination ):
99
104
100
- def __init__ (self , client : Client , cursor_path : Dict [str , Any ]):
105
+ def __init__ (self , client : " Client" , cursor_path : Dict [str , Any ]):
101
106
self .client = client
102
107
self .cursor_path = cursor_path
103
108
self .next_cursor : Optional [str ] = None
@@ -119,7 +124,7 @@ def fetch_results(self, query: str, params: Dict[str, Any],
119
124
120
125
class _OffsetPagination (_Pagination ):
121
126
122
- def __init__ (self , client ):
127
+ def __init__ (self , client : "Client" ):
123
128
self .client = client
124
129
self ._fetched_pages = 0
125
130
0 commit comments