Skip to content

Commit ac2099e

Browse files
committed
chore: lazy load raw resource class properties (#144)
1 parent 50b7de9 commit ac2099e

23 files changed

Lines changed: 316 additions & 40 deletions

src/orb/resources/beta/beta.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,35 @@ def with_streaming_response(self) -> AsyncBetaWithStreamingResponse:
4646

4747
class BetaWithRawResponse:
4848
def __init__(self, beta: Beta) -> None:
49-
self.price = PriceWithRawResponse(beta.price)
49+
self._beta = beta
50+
51+
@cached_property
52+
def price(self) -> PriceWithRawResponse:
53+
return PriceWithRawResponse(self._beta.price)
5054

5155

5256
class AsyncBetaWithRawResponse:
5357
def __init__(self, beta: AsyncBeta) -> None:
54-
self.price = AsyncPriceWithRawResponse(beta.price)
58+
self._beta = beta
59+
60+
@cached_property
61+
def price(self) -> AsyncPriceWithRawResponse:
62+
return AsyncPriceWithRawResponse(self._beta.price)
5563

5664

5765
class BetaWithStreamingResponse:
5866
def __init__(self, beta: Beta) -> None:
59-
self.price = PriceWithStreamingResponse(beta.price)
67+
self._beta = beta
68+
69+
@cached_property
70+
def price(self) -> PriceWithStreamingResponse:
71+
return PriceWithStreamingResponse(self._beta.price)
6072

6173

6274
class AsyncBetaWithStreamingResponse:
6375
def __init__(self, beta: AsyncBeta) -> None:
64-
self.price = AsyncPriceWithStreamingResponse(beta.price)
76+
self._beta = beta
77+
78+
@cached_property
79+
def price(self) -> AsyncPriceWithStreamingResponse:
80+
return AsyncPriceWithStreamingResponse(self._beta.price)

src/orb/resources/beta/price.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,35 @@ async def evaluate(
229229

230230
class PriceWithRawResponse:
231231
def __init__(self, price: Price) -> None:
232+
self._price = price
233+
232234
self.evaluate = _legacy_response.to_raw_response_wrapper(
233235
price.evaluate,
234236
)
235237

236238

237239
class AsyncPriceWithRawResponse:
238240
def __init__(self, price: AsyncPrice) -> None:
241+
self._price = price
242+
239243
self.evaluate = _legacy_response.async_to_raw_response_wrapper(
240244
price.evaluate,
241245
)
242246

243247

244248
class PriceWithStreamingResponse:
245249
def __init__(self, price: Price) -> None:
250+
self._price = price
251+
246252
self.evaluate = to_streamed_response_wrapper(
247253
price.evaluate,
248254
)
249255

250256

251257
class AsyncPriceWithStreamingResponse:
252258
def __init__(self, price: AsyncPrice) -> None:
259+
self._price = price
260+
253261
self.evaluate = async_to_streamed_response_wrapper(
254262
price.evaluate,
255263
)

src/orb/resources/coupons/coupons.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ async def fetch(
460460

461461
class CouponsWithRawResponse:
462462
def __init__(self, coupons: Coupons) -> None:
463-
self.subscriptions = SubscriptionsWithRawResponse(coupons.subscriptions)
463+
self._coupons = coupons
464464

465465
self.create = _legacy_response.to_raw_response_wrapper(
466466
coupons.create,
@@ -475,10 +475,14 @@ def __init__(self, coupons: Coupons) -> None:
475475
coupons.fetch,
476476
)
477477

478+
@cached_property
479+
def subscriptions(self) -> SubscriptionsWithRawResponse:
480+
return SubscriptionsWithRawResponse(self._coupons.subscriptions)
481+
478482

479483
class AsyncCouponsWithRawResponse:
480484
def __init__(self, coupons: AsyncCoupons) -> None:
481-
self.subscriptions = AsyncSubscriptionsWithRawResponse(coupons.subscriptions)
485+
self._coupons = coupons
482486

483487
self.create = _legacy_response.async_to_raw_response_wrapper(
484488
coupons.create,
@@ -493,10 +497,14 @@ def __init__(self, coupons: AsyncCoupons) -> None:
493497
coupons.fetch,
494498
)
495499

500+
@cached_property
501+
def subscriptions(self) -> AsyncSubscriptionsWithRawResponse:
502+
return AsyncSubscriptionsWithRawResponse(self._coupons.subscriptions)
503+
496504

497505
class CouponsWithStreamingResponse:
498506
def __init__(self, coupons: Coupons) -> None:
499-
self.subscriptions = SubscriptionsWithStreamingResponse(coupons.subscriptions)
507+
self._coupons = coupons
500508

501509
self.create = to_streamed_response_wrapper(
502510
coupons.create,
@@ -511,10 +519,14 @@ def __init__(self, coupons: Coupons) -> None:
511519
coupons.fetch,
512520
)
513521

522+
@cached_property
523+
def subscriptions(self) -> SubscriptionsWithStreamingResponse:
524+
return SubscriptionsWithStreamingResponse(self._coupons.subscriptions)
525+
514526

515527
class AsyncCouponsWithStreamingResponse:
516528
def __init__(self, coupons: AsyncCoupons) -> None:
517-
self.subscriptions = AsyncSubscriptionsWithStreamingResponse(coupons.subscriptions)
529+
self._coupons = coupons
518530

519531
self.create = async_to_streamed_response_wrapper(
520532
coupons.create,
@@ -528,3 +540,7 @@ def __init__(self, coupons: AsyncCoupons) -> None:
528540
self.fetch = async_to_streamed_response_wrapper(
529541
coupons.fetch,
530542
)
543+
544+
@cached_property
545+
def subscriptions(self) -> AsyncSubscriptionsWithStreamingResponse:
546+
return AsyncSubscriptionsWithStreamingResponse(self._coupons.subscriptions)

src/orb/resources/coupons/subscriptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,27 +153,35 @@ def list(
153153

154154
class SubscriptionsWithRawResponse:
155155
def __init__(self, subscriptions: Subscriptions) -> None:
156+
self._subscriptions = subscriptions
157+
156158
self.list = _legacy_response.to_raw_response_wrapper(
157159
subscriptions.list,
158160
)
159161

160162

161163
class AsyncSubscriptionsWithRawResponse:
162164
def __init__(self, subscriptions: AsyncSubscriptions) -> None:
165+
self._subscriptions = subscriptions
166+
163167
self.list = _legacy_response.async_to_raw_response_wrapper(
164168
subscriptions.list,
165169
)
166170

167171

168172
class SubscriptionsWithStreamingResponse:
169173
def __init__(self, subscriptions: Subscriptions) -> None:
174+
self._subscriptions = subscriptions
175+
170176
self.list = to_streamed_response_wrapper(
171177
subscriptions.list,
172178
)
173179

174180

175181
class AsyncSubscriptionsWithStreamingResponse:
176182
def __init__(self, subscriptions: AsyncSubscriptions) -> None:
183+
self._subscriptions = subscriptions
184+
177185
self.list = async_to_streamed_response_wrapper(
178186
subscriptions.list,
179187
)

src/orb/resources/credit_notes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ async def fetch(
214214

215215
class CreditNotesWithRawResponse:
216216
def __init__(self, credit_notes: CreditNotes) -> None:
217+
self._credit_notes = credit_notes
218+
217219
self.list = _legacy_response.to_raw_response_wrapper(
218220
credit_notes.list,
219221
)
@@ -224,6 +226,8 @@ def __init__(self, credit_notes: CreditNotes) -> None:
224226

225227
class AsyncCreditNotesWithRawResponse:
226228
def __init__(self, credit_notes: AsyncCreditNotes) -> None:
229+
self._credit_notes = credit_notes
230+
227231
self.list = _legacy_response.async_to_raw_response_wrapper(
228232
credit_notes.list,
229233
)
@@ -234,6 +238,8 @@ def __init__(self, credit_notes: AsyncCreditNotes) -> None:
234238

235239
class CreditNotesWithStreamingResponse:
236240
def __init__(self, credit_notes: CreditNotes) -> None:
241+
self._credit_notes = credit_notes
242+
237243
self.list = to_streamed_response_wrapper(
238244
credit_notes.list,
239245
)
@@ -244,6 +250,8 @@ def __init__(self, credit_notes: CreditNotes) -> None:
244250

245251
class AsyncCreditNotesWithStreamingResponse:
246252
def __init__(self, credit_notes: AsyncCreditNotes) -> None:
253+
self._credit_notes = credit_notes
254+
247255
self.list = async_to_streamed_response_wrapper(
248256
credit_notes.list,
249257
)

src/orb/resources/customers/balance_transactions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ def list(
331331

332332
class BalanceTransactionsWithRawResponse:
333333
def __init__(self, balance_transactions: BalanceTransactions) -> None:
334+
self._balance_transactions = balance_transactions
335+
334336
self.create = _legacy_response.to_raw_response_wrapper(
335337
balance_transactions.create,
336338
)
@@ -341,6 +343,8 @@ def __init__(self, balance_transactions: BalanceTransactions) -> None:
341343

342344
class AsyncBalanceTransactionsWithRawResponse:
343345
def __init__(self, balance_transactions: AsyncBalanceTransactions) -> None:
346+
self._balance_transactions = balance_transactions
347+
344348
self.create = _legacy_response.async_to_raw_response_wrapper(
345349
balance_transactions.create,
346350
)
@@ -351,6 +355,8 @@ def __init__(self, balance_transactions: AsyncBalanceTransactions) -> None:
351355

352356
class BalanceTransactionsWithStreamingResponse:
353357
def __init__(self, balance_transactions: BalanceTransactions) -> None:
358+
self._balance_transactions = balance_transactions
359+
354360
self.create = to_streamed_response_wrapper(
355361
balance_transactions.create,
356362
)
@@ -361,6 +367,8 @@ def __init__(self, balance_transactions: BalanceTransactions) -> None:
361367

362368
class AsyncBalanceTransactionsWithStreamingResponse:
363369
def __init__(self, balance_transactions: AsyncBalanceTransactions) -> None:
370+
self._balance_transactions = balance_transactions
371+
364372
self.create = async_to_streamed_response_wrapper(
365373
balance_transactions.create,
366374
)

src/orb/resources/customers/costs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ async def list_by_external_id(
825825

826826
class CostsWithRawResponse:
827827
def __init__(self, costs: Costs) -> None:
828+
self._costs = costs
829+
828830
self.list = _legacy_response.to_raw_response_wrapper(
829831
costs.list,
830832
)
@@ -835,6 +837,8 @@ def __init__(self, costs: Costs) -> None:
835837

836838
class AsyncCostsWithRawResponse:
837839
def __init__(self, costs: AsyncCosts) -> None:
840+
self._costs = costs
841+
838842
self.list = _legacy_response.async_to_raw_response_wrapper(
839843
costs.list,
840844
)
@@ -845,6 +849,8 @@ def __init__(self, costs: AsyncCosts) -> None:
845849

846850
class CostsWithStreamingResponse:
847851
def __init__(self, costs: Costs) -> None:
852+
self._costs = costs
853+
848854
self.list = to_streamed_response_wrapper(
849855
costs.list,
850856
)
@@ -855,6 +861,8 @@ def __init__(self, costs: Costs) -> None:
855861

856862
class AsyncCostsWithStreamingResponse:
857863
def __init__(self, costs: AsyncCosts) -> None:
864+
self._costs = costs
865+
858866
self.list = async_to_streamed_response_wrapper(
859867
costs.list,
860868
)

src/orb/resources/customers/credits/credits.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def list_by_external_id(
289289

290290
class CreditsWithRawResponse:
291291
def __init__(self, credits: Credits) -> None:
292-
self.ledger = LedgerWithRawResponse(credits.ledger)
292+
self._credits = credits
293293

294294
self.list = _legacy_response.to_raw_response_wrapper(
295295
credits.list,
@@ -298,10 +298,14 @@ def __init__(self, credits: Credits) -> None:
298298
credits.list_by_external_id,
299299
)
300300

301+
@cached_property
302+
def ledger(self) -> LedgerWithRawResponse:
303+
return LedgerWithRawResponse(self._credits.ledger)
304+
301305

302306
class AsyncCreditsWithRawResponse:
303307
def __init__(self, credits: AsyncCredits) -> None:
304-
self.ledger = AsyncLedgerWithRawResponse(credits.ledger)
308+
self._credits = credits
305309

306310
self.list = _legacy_response.async_to_raw_response_wrapper(
307311
credits.list,
@@ -310,10 +314,14 @@ def __init__(self, credits: AsyncCredits) -> None:
310314
credits.list_by_external_id,
311315
)
312316

317+
@cached_property
318+
def ledger(self) -> AsyncLedgerWithRawResponse:
319+
return AsyncLedgerWithRawResponse(self._credits.ledger)
320+
313321

314322
class CreditsWithStreamingResponse:
315323
def __init__(self, credits: Credits) -> None:
316-
self.ledger = LedgerWithStreamingResponse(credits.ledger)
324+
self._credits = credits
317325

318326
self.list = to_streamed_response_wrapper(
319327
credits.list,
@@ -322,14 +330,22 @@ def __init__(self, credits: Credits) -> None:
322330
credits.list_by_external_id,
323331
)
324332

333+
@cached_property
334+
def ledger(self) -> LedgerWithStreamingResponse:
335+
return LedgerWithStreamingResponse(self._credits.ledger)
336+
325337

326338
class AsyncCreditsWithStreamingResponse:
327339
def __init__(self, credits: AsyncCredits) -> None:
328-
self.ledger = AsyncLedgerWithStreamingResponse(credits.ledger)
340+
self._credits = credits
329341

330342
self.list = async_to_streamed_response_wrapper(
331343
credits.list,
332344
)
333345
self.list_by_external_id = async_to_streamed_response_wrapper(
334346
credits.list_by_external_id,
335347
)
348+
349+
@cached_property
350+
def ledger(self) -> AsyncLedgerWithStreamingResponse:
351+
return AsyncLedgerWithStreamingResponse(self._credits.ledger)

src/orb/resources/customers/credits/ledger.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,6 +4279,8 @@ def list_by_external_id(
42794279

42804280
class LedgerWithRawResponse:
42814281
def __init__(self, ledger: Ledger) -> None:
4282+
self._ledger = ledger
4283+
42824284
self.list = _legacy_response.to_raw_response_wrapper(
42834285
ledger.list,
42844286
)
@@ -4295,6 +4297,8 @@ def __init__(self, ledger: Ledger) -> None:
42954297

42964298
class AsyncLedgerWithRawResponse:
42974299
def __init__(self, ledger: AsyncLedger) -> None:
4300+
self._ledger = ledger
4301+
42984302
self.list = _legacy_response.async_to_raw_response_wrapper(
42994303
ledger.list,
43004304
)
@@ -4311,6 +4315,8 @@ def __init__(self, ledger: AsyncLedger) -> None:
43114315

43124316
class LedgerWithStreamingResponse:
43134317
def __init__(self, ledger: Ledger) -> None:
4318+
self._ledger = ledger
4319+
43144320
self.list = to_streamed_response_wrapper(
43154321
ledger.list,
43164322
)
@@ -4327,6 +4333,8 @@ def __init__(self, ledger: Ledger) -> None:
43274333

43284334
class AsyncLedgerWithStreamingResponse:
43294335
def __init__(self, ledger: AsyncLedger) -> None:
4336+
self._ledger = ledger
4337+
43304338
self.list = async_to_streamed_response_wrapper(
43314339
ledger.list,
43324340
)

0 commit comments

Comments
 (0)