|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import os |
6 | | -from typing import Any, Mapping |
| 6 | +from typing import TYPE_CHECKING, Any, Mapping |
7 | 7 | from typing_extensions import Self, override |
8 | 8 |
|
9 | 9 | import httpx |
|
20 | 20 | not_given, |
21 | 21 | ) |
22 | 22 | from ._utils import is_given, get_async_library |
| 23 | +from ._compat import cached_property |
23 | 24 | from ._version import __version__ |
24 | | -from .resources import task_run |
25 | 25 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
26 | 26 | from ._exceptions import ParallelError, APIStatusError |
27 | 27 | from ._base_client import ( |
28 | 28 | DEFAULT_MAX_RETRIES, |
29 | 29 | SyncAPIClient, |
30 | 30 | AsyncAPIClient, |
31 | 31 | ) |
32 | | -from .resources.beta import beta |
| 32 | + |
| 33 | +if TYPE_CHECKING: |
| 34 | + from .resources import beta, task_run |
| 35 | + from .resources.task_run import TaskRunResource, AsyncTaskRunResource |
| 36 | + from .resources.beta.beta import BetaResource, AsyncBetaResource |
33 | 37 |
|
34 | 38 | __all__ = [ |
35 | 39 | "Timeout", |
|
44 | 48 |
|
45 | 49 |
|
46 | 50 | class Parallel(SyncAPIClient): |
47 | | - task_run: task_run.TaskRunResource |
48 | | - beta: beta.BetaResource |
49 | | - with_raw_response: ParallelWithRawResponse |
50 | | - with_streaming_response: ParallelWithStreamedResponse |
51 | | - |
52 | 51 | # client options |
53 | 52 | api_key: str |
54 | 53 |
|
@@ -103,10 +102,25 @@ def __init__( |
103 | 102 | _strict_response_validation=_strict_response_validation, |
104 | 103 | ) |
105 | 104 |
|
106 | | - self.task_run = task_run.TaskRunResource(self) |
107 | | - self.beta = beta.BetaResource(self) |
108 | | - self.with_raw_response = ParallelWithRawResponse(self) |
109 | | - self.with_streaming_response = ParallelWithStreamedResponse(self) |
| 105 | + @cached_property |
| 106 | + def task_run(self) -> TaskRunResource: |
| 107 | + from .resources.task_run import TaskRunResource |
| 108 | + |
| 109 | + return TaskRunResource(self) |
| 110 | + |
| 111 | + @cached_property |
| 112 | + def beta(self) -> BetaResource: |
| 113 | + from .resources.beta import BetaResource |
| 114 | + |
| 115 | + return BetaResource(self) |
| 116 | + |
| 117 | + @cached_property |
| 118 | + def with_raw_response(self) -> ParallelWithRawResponse: |
| 119 | + return ParallelWithRawResponse(self) |
| 120 | + |
| 121 | + @cached_property |
| 122 | + def with_streaming_response(self) -> ParallelWithStreamedResponse: |
| 123 | + return ParallelWithStreamedResponse(self) |
110 | 124 |
|
111 | 125 | @property |
112 | 126 | @override |
@@ -214,11 +228,6 @@ def _make_status_error( |
214 | 228 |
|
215 | 229 |
|
216 | 230 | class AsyncParallel(AsyncAPIClient): |
217 | | - task_run: task_run.AsyncTaskRunResource |
218 | | - beta: beta.AsyncBetaResource |
219 | | - with_raw_response: AsyncParallelWithRawResponse |
220 | | - with_streaming_response: AsyncParallelWithStreamedResponse |
221 | | - |
222 | 231 | # client options |
223 | 232 | api_key: str |
224 | 233 |
|
@@ -273,10 +282,25 @@ def __init__( |
273 | 282 | _strict_response_validation=_strict_response_validation, |
274 | 283 | ) |
275 | 284 |
|
276 | | - self.task_run = task_run.AsyncTaskRunResource(self) |
277 | | - self.beta = beta.AsyncBetaResource(self) |
278 | | - self.with_raw_response = AsyncParallelWithRawResponse(self) |
279 | | - self.with_streaming_response = AsyncParallelWithStreamedResponse(self) |
| 285 | + @cached_property |
| 286 | + def task_run(self) -> AsyncTaskRunResource: |
| 287 | + from .resources.task_run import AsyncTaskRunResource |
| 288 | + |
| 289 | + return AsyncTaskRunResource(self) |
| 290 | + |
| 291 | + @cached_property |
| 292 | + def beta(self) -> AsyncBetaResource: |
| 293 | + from .resources.beta import AsyncBetaResource |
| 294 | + |
| 295 | + return AsyncBetaResource(self) |
| 296 | + |
| 297 | + @cached_property |
| 298 | + def with_raw_response(self) -> AsyncParallelWithRawResponse: |
| 299 | + return AsyncParallelWithRawResponse(self) |
| 300 | + |
| 301 | + @cached_property |
| 302 | + def with_streaming_response(self) -> AsyncParallelWithStreamedResponse: |
| 303 | + return AsyncParallelWithStreamedResponse(self) |
280 | 304 |
|
281 | 305 | @property |
282 | 306 | @override |
@@ -384,27 +408,79 @@ def _make_status_error( |
384 | 408 |
|
385 | 409 |
|
386 | 410 | class ParallelWithRawResponse: |
| 411 | + _client: Parallel |
| 412 | + |
387 | 413 | def __init__(self, client: Parallel) -> None: |
388 | | - self.task_run = task_run.TaskRunResourceWithRawResponse(client.task_run) |
389 | | - self.beta = beta.BetaResourceWithRawResponse(client.beta) |
| 414 | + self._client = client |
| 415 | + |
| 416 | + @cached_property |
| 417 | + def task_run(self) -> task_run.TaskRunResourceWithRawResponse: |
| 418 | + from .resources.task_run import TaskRunResourceWithRawResponse |
| 419 | + |
| 420 | + return TaskRunResourceWithRawResponse(self._client.task_run) |
| 421 | + |
| 422 | + @cached_property |
| 423 | + def beta(self) -> beta.BetaResourceWithRawResponse: |
| 424 | + from .resources.beta import BetaResourceWithRawResponse |
| 425 | + |
| 426 | + return BetaResourceWithRawResponse(self._client.beta) |
390 | 427 |
|
391 | 428 |
|
392 | 429 | class AsyncParallelWithRawResponse: |
| 430 | + _client: AsyncParallel |
| 431 | + |
393 | 432 | def __init__(self, client: AsyncParallel) -> None: |
394 | | - self.task_run = task_run.AsyncTaskRunResourceWithRawResponse(client.task_run) |
395 | | - self.beta = beta.AsyncBetaResourceWithRawResponse(client.beta) |
| 433 | + self._client = client |
| 434 | + |
| 435 | + @cached_property |
| 436 | + def task_run(self) -> task_run.AsyncTaskRunResourceWithRawResponse: |
| 437 | + from .resources.task_run import AsyncTaskRunResourceWithRawResponse |
| 438 | + |
| 439 | + return AsyncTaskRunResourceWithRawResponse(self._client.task_run) |
| 440 | + |
| 441 | + @cached_property |
| 442 | + def beta(self) -> beta.AsyncBetaResourceWithRawResponse: |
| 443 | + from .resources.beta import AsyncBetaResourceWithRawResponse |
| 444 | + |
| 445 | + return AsyncBetaResourceWithRawResponse(self._client.beta) |
396 | 446 |
|
397 | 447 |
|
398 | 448 | class ParallelWithStreamedResponse: |
| 449 | + _client: Parallel |
| 450 | + |
399 | 451 | def __init__(self, client: Parallel) -> None: |
400 | | - self.task_run = task_run.TaskRunResourceWithStreamingResponse(client.task_run) |
401 | | - self.beta = beta.BetaResourceWithStreamingResponse(client.beta) |
| 452 | + self._client = client |
| 453 | + |
| 454 | + @cached_property |
| 455 | + def task_run(self) -> task_run.TaskRunResourceWithStreamingResponse: |
| 456 | + from .resources.task_run import TaskRunResourceWithStreamingResponse |
| 457 | + |
| 458 | + return TaskRunResourceWithStreamingResponse(self._client.task_run) |
| 459 | + |
| 460 | + @cached_property |
| 461 | + def beta(self) -> beta.BetaResourceWithStreamingResponse: |
| 462 | + from .resources.beta import BetaResourceWithStreamingResponse |
| 463 | + |
| 464 | + return BetaResourceWithStreamingResponse(self._client.beta) |
402 | 465 |
|
403 | 466 |
|
404 | 467 | class AsyncParallelWithStreamedResponse: |
| 468 | + _client: AsyncParallel |
| 469 | + |
405 | 470 | def __init__(self, client: AsyncParallel) -> None: |
406 | | - self.task_run = task_run.AsyncTaskRunResourceWithStreamingResponse(client.task_run) |
407 | | - self.beta = beta.AsyncBetaResourceWithStreamingResponse(client.beta) |
| 471 | + self._client = client |
| 472 | + |
| 473 | + @cached_property |
| 474 | + def task_run(self) -> task_run.AsyncTaskRunResourceWithStreamingResponse: |
| 475 | + from .resources.task_run import AsyncTaskRunResourceWithStreamingResponse |
| 476 | + |
| 477 | + return AsyncTaskRunResourceWithStreamingResponse(self._client.task_run) |
| 478 | + |
| 479 | + @cached_property |
| 480 | + def beta(self) -> beta.AsyncBetaResourceWithStreamingResponse: |
| 481 | + from .resources.beta import AsyncBetaResourceWithStreamingResponse |
| 482 | + |
| 483 | + return AsyncBetaResourceWithStreamingResponse(self._client.beta) |
408 | 484 |
|
409 | 485 |
|
410 | 486 | Client = Parallel |
|
0 commit comments