Skip to content

Commit 995537f

Browse files
chore: speedup initial import
1 parent a0aab9c commit 995537f

1 file changed

Lines changed: 68 additions & 20 deletions

File tree

src/brand/dev/_client.py

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Any, Mapping
6+
from typing import TYPE_CHECKING, Any, Mapping
77
from typing_extensions import Self, override
88

99
import httpx
@@ -20,8 +20,8 @@
2020
not_given,
2121
)
2222
from ._utils import is_given, get_async_library
23+
from ._compat import cached_property
2324
from ._version import __version__
24-
from .resources import brand
2525
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2626
from ._exceptions import BrandDevError, APIStatusError
2727
from ._base_client import (
@@ -30,6 +30,10 @@
3030
AsyncAPIClient,
3131
)
3232

33+
if TYPE_CHECKING:
34+
from .resources import brand
35+
from .resources.brand import BrandResource, AsyncBrandResource
36+
3337
__all__ = [
3438
"Timeout",
3539
"Transport",
@@ -43,10 +47,6 @@
4347

4448

4549
class BrandDev(SyncAPIClient):
46-
brand: brand.BrandResource
47-
with_raw_response: BrandDevWithRawResponse
48-
with_streaming_response: BrandDevWithStreamedResponse
49-
5050
# client options
5151
api_key: str
5252

@@ -101,9 +101,19 @@ def __init__(
101101
_strict_response_validation=_strict_response_validation,
102102
)
103103

104-
self.brand = brand.BrandResource(self)
105-
self.with_raw_response = BrandDevWithRawResponse(self)
106-
self.with_streaming_response = BrandDevWithStreamedResponse(self)
104+
@cached_property
105+
def brand(self) -> BrandResource:
106+
from .resources.brand import BrandResource
107+
108+
return BrandResource(self)
109+
110+
@cached_property
111+
def with_raw_response(self) -> BrandDevWithRawResponse:
112+
return BrandDevWithRawResponse(self)
113+
114+
@cached_property
115+
def with_streaming_response(self) -> BrandDevWithStreamedResponse:
116+
return BrandDevWithStreamedResponse(self)
107117

108118
@property
109119
@override
@@ -211,10 +221,6 @@ def _make_status_error(
211221

212222

213223
class AsyncBrandDev(AsyncAPIClient):
214-
brand: brand.AsyncBrandResource
215-
with_raw_response: AsyncBrandDevWithRawResponse
216-
with_streaming_response: AsyncBrandDevWithStreamedResponse
217-
218224
# client options
219225
api_key: str
220226

@@ -269,9 +275,19 @@ def __init__(
269275
_strict_response_validation=_strict_response_validation,
270276
)
271277

272-
self.brand = brand.AsyncBrandResource(self)
273-
self.with_raw_response = AsyncBrandDevWithRawResponse(self)
274-
self.with_streaming_response = AsyncBrandDevWithStreamedResponse(self)
278+
@cached_property
279+
def brand(self) -> AsyncBrandResource:
280+
from .resources.brand import AsyncBrandResource
281+
282+
return AsyncBrandResource(self)
283+
284+
@cached_property
285+
def with_raw_response(self) -> AsyncBrandDevWithRawResponse:
286+
return AsyncBrandDevWithRawResponse(self)
287+
288+
@cached_property
289+
def with_streaming_response(self) -> AsyncBrandDevWithStreamedResponse:
290+
return AsyncBrandDevWithStreamedResponse(self)
275291

276292
@property
277293
@override
@@ -379,23 +395,55 @@ def _make_status_error(
379395

380396

381397
class BrandDevWithRawResponse:
398+
_client: BrandDev
399+
382400
def __init__(self, client: BrandDev) -> None:
383-
self.brand = brand.BrandResourceWithRawResponse(client.brand)
401+
self._client = client
402+
403+
@cached_property
404+
def brand(self) -> brand.BrandResourceWithRawResponse:
405+
from .resources.brand import BrandResourceWithRawResponse
406+
407+
return BrandResourceWithRawResponse(self._client.brand)
384408

385409

386410
class AsyncBrandDevWithRawResponse:
411+
_client: AsyncBrandDev
412+
387413
def __init__(self, client: AsyncBrandDev) -> None:
388-
self.brand = brand.AsyncBrandResourceWithRawResponse(client.brand)
414+
self._client = client
415+
416+
@cached_property
417+
def brand(self) -> brand.AsyncBrandResourceWithRawResponse:
418+
from .resources.brand import AsyncBrandResourceWithRawResponse
419+
420+
return AsyncBrandResourceWithRawResponse(self._client.brand)
389421

390422

391423
class BrandDevWithStreamedResponse:
424+
_client: BrandDev
425+
392426
def __init__(self, client: BrandDev) -> None:
393-
self.brand = brand.BrandResourceWithStreamingResponse(client.brand)
427+
self._client = client
428+
429+
@cached_property
430+
def brand(self) -> brand.BrandResourceWithStreamingResponse:
431+
from .resources.brand import BrandResourceWithStreamingResponse
432+
433+
return BrandResourceWithStreamingResponse(self._client.brand)
394434

395435

396436
class AsyncBrandDevWithStreamedResponse:
437+
_client: AsyncBrandDev
438+
397439
def __init__(self, client: AsyncBrandDev) -> None:
398-
self.brand = brand.AsyncBrandResourceWithStreamingResponse(client.brand)
440+
self._client = client
441+
442+
@cached_property
443+
def brand(self) -> brand.AsyncBrandResourceWithStreamingResponse:
444+
from .resources.brand import AsyncBrandResourceWithStreamingResponse
445+
446+
return AsyncBrandResourceWithStreamingResponse(self._client.brand)
399447

400448

401449
Client = BrandDev

0 commit comments

Comments
 (0)