Skip to content

Commit 93012c5

Browse files
author
Matt Sokoloff
committed
recommended changes
1 parent b2e11e7 commit 93012c5

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

labelbox/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,8 @@ def convert_value(value):
124124
data = json.dumps({'query': query, 'variables': params}).encode('utf-8')
125125

126126
try:
127-
endpoint = self.endpoint
128-
if beta:
129-
endpoint = endpoint.replace('/graphql', '/_gql')
130-
131-
response = requests.post(endpoint,
127+
response = requests.post(self.endpoint.replace('/graphql', '/_gql')
128+
if beta else self.endpoint,
132129
data=data,
133130
headers=self.headers,
134131
timeout=timeout)

labelbox/orm/db_object.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime, timezone
2-
from functools import partial
2+
from functools import wraps
33
import logging
44

55
from labelbox import utils
@@ -258,11 +258,12 @@ def delete(self):
258258

259259
def beta(fn):
260260

261+
@wraps(fn)
261262
def wrapper(self, *args, **kwargs):
262263
if not self.client.enable_beta:
263264
raise Exception(
264265
f"This function {fn.__name__} relies on a beta feature in the api. This means that the interface could change."
265-
" Set `enable_beta=True` in the client to enable use of these functions."
266+
" Set `enable_beta=True` in the client to enable use of beta functions."
266267
)
267268
return fn(self, *args, **kwargs)
268269

labelbox/pagination.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Size of a single page in a paginated query.
22
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
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

98103
class _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

120125
class _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

Comments
 (0)