Skip to content

Commit 64429e8

Browse files
authored
Add docstring for _batch (#144)
1 parent 3dadd91 commit 64429e8

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/yandex_cloud_ml_sdk/_batch/domain.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717
from yandex_cloud_ml_sdk._types.batch.task_info import BatchTaskInfo
1818
from yandex_cloud_ml_sdk._types.domain import BaseDomain
1919
from yandex_cloud_ml_sdk._types.misc import UNDEFINED, UndefinedOr, get_defined_value
20+
from yandex_cloud_ml_sdk._utils.doc import doc_from
2021
from yandex_cloud_ml_sdk._utils.proto import ProtoEnumCoercible
2122
from yandex_cloud_ml_sdk._utils.sync import run_sync, run_sync_generator
2223

2324
logger = get_logger(__name__)
2425

2526

2627
class BaseBatch(BaseDomain, Generic[BatchTaskOperationTypeT]):
28+
"""
29+
Сlass for managing batch operations in Yandex Cloud ML SDK.
30+
31+
For usage examples see `batch example <https://github.com/yandex-cloud/yandex-cloud-ml-sdk/blob/master/examples/{link}/completions/batch.py>`_.
32+
"""
2733
_operation_impl: type[BatchTaskOperationTypeT]
2834

2935
async def _get(
@@ -32,6 +38,13 @@ async def _get(
3238
*,
3339
timeout: float = 60,
3440
) -> BatchTaskOperationTypeT:
41+
"""
42+
Get batch task operation by ID or by BatchTaskInfo object.
43+
44+
:param task: Either task ID string or BatchTaskInfo object.
45+
:param timeout: The timeout, or the maximum time to wait for the request to complete in seconds.
46+
Defaults to 60 seconds.
47+
"""
3548
logger.debug('Fetching batch task %s from server', task)
3649

3750
if isinstance(task, BatchTaskInfo):
@@ -59,6 +72,14 @@ async def _list_operations(
5972
status: UndefinedOr[ProtoEnumCoercible[BatchTaskStatus]] = UNDEFINED,
6073
timeout: float = 60,
6174
) -> AsyncIterator[BatchTaskOperationTypeT]:
75+
"""
76+
List batch task operations with optional filtering.
77+
78+
:param page_size: Maximum number of tasks per page (optional).
79+
:param status: Filter tasks by status (optional).
80+
:param timeout: The timeout, or the maximum time to wait for the request to complete in seconds.
81+
Defaults to 60 seconds.
82+
"""
6283
logger.debug('Fetching batch task list')
6384

6485
async for task_proto in self._list_impl(
@@ -78,6 +99,14 @@ async def _list_info(
7899
status: UndefinedOr[ProtoEnumCoercible[BatchTaskStatus]] = UNDEFINED,
79100
timeout: float = 60,
80101
) -> AsyncIterator[BatchTaskInfo]:
102+
"""
103+
List batch task information with optional filtering.
104+
105+
:param page_size: Maximum number of tasks per page (optional).
106+
:param status: Filter tasks by status (optional).
107+
:param timeout: The timeout, or the maximum time to wait for the request to complete in seconds.
108+
Defaults to 60 seconds.
109+
"""
81110
logger.debug('Fetching batch task list')
82111

83112
async for task_proto in self._list_impl(
@@ -138,9 +167,11 @@ async def _list_impl(
138167
page_token = response.next_page_token
139168

140169

170+
@doc_from(BaseBatch, link="async")
141171
class AsyncBatch(BaseBatch[AsyncBatchTaskOperation]):
142172
_operation_impl = AsyncBatchTaskOperation
143173

174+
@doc_from(BaseBatch._get)
144175
async def get(
145176
self,
146177
task: str | BatchTaskInfo,
@@ -149,6 +180,7 @@ async def get(
149180
) -> AsyncBatchTaskOperation:
150181
return await self._get(task=task, timeout=timeout)
151182

183+
@doc_from(BaseBatch._list_operations)
152184
async def list_operations(
153185
self,
154186
*,
@@ -163,6 +195,7 @@ async def list_operations(
163195
):
164196
yield task
165197

198+
@doc_from(BaseBatch._list_info)
166199
async def list_info(
167200
self,
168201
*,
@@ -177,13 +210,14 @@ async def list_info(
177210
):
178211
yield task
179212

180-
213+
@doc_from(BaseBatch, link="sync")
181214
class Batch(BaseBatch[BatchTaskOperation]):
182215
_operation_impl = BatchTaskOperation
183216
__get = run_sync(BaseBatch._get)
184217
__list_operations = run_sync_generator(BaseBatch._list_operations)
185218
__list_info = run_sync_generator(BaseBatch._list_info)
186219

220+
@doc_from(BaseBatch._get)
187221
def get(
188222
self,
189223
task: str | BatchTaskInfo,
@@ -192,6 +226,7 @@ def get(
192226
) -> BatchTaskOperation:
193227
return self.__get(task=task, timeout=timeout)
194228

229+
@doc_from(BaseBatch._list_operations)
195230
def list_operations(
196231
self,
197232
*,
@@ -205,6 +240,7 @@ def list_operations(
205240
timeout=timeout
206241
)
207242

243+
@doc_from(BaseBatch._list_info)
208244
def list_info(
209245
self,
210246
*,

0 commit comments

Comments
 (0)