From eb2c3ff6f01d1870d9bfdc8c602b01695d6ad66b Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Thu, 4 Jan 2024 21:25:44 +0000 Subject: [PATCH] chore: use property declarations for resource members This will speedup client instantiation in certain cases. --- pyproject.toml | 1 + src/orb/_compat.py | 10 +++ src/orb/resources/coupons/coupons.py | 30 ++++---- src/orb/resources/coupons/subscriptions.py | 22 +++--- src/orb/resources/credit_notes.py | 22 +++--- .../customers/balance_transactions.py | 22 +++--- src/orb/resources/customers/costs.py | 22 +++--- .../resources/customers/credits/credits.py | 30 ++++---- src/orb/resources/customers/credits/ledger.py | 22 +++--- src/orb/resources/customers/customers.py | 71 +++++++++++-------- src/orb/resources/customers/usage.py | 22 +++--- src/orb/resources/events/backfills.py | 22 +++--- src/orb/resources/events/events.py | 30 ++++---- src/orb/resources/invoice_line_items.py | 27 +++---- src/orb/resources/invoices.py | 22 +++--- src/orb/resources/items.py | 22 +++--- src/orb/resources/metrics.py | 22 +++--- src/orb/resources/plans/external_plan_id.py | 22 +++--- src/orb/resources/plans/plans.py | 30 ++++---- src/orb/resources/prices/external_price_id.py | 22 +++--- src/orb/resources/prices/prices.py | 30 ++++---- src/orb/resources/subscriptions.py | 22 +++--- src/orb/resources/top_level.py | 22 ++---- 23 files changed, 242 insertions(+), 325 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9e99a362..e84d551a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ dependencies = [ "anyio>=3.5.0, <5", "distro>=1.7.0, <2", "sniffio", + "cached-property; python_version < '3.8'", ] requires-python = ">= 3.7" diff --git a/src/orb/_compat.py b/src/orb/_compat.py index d95db8ed..3cda3990 100644 --- a/src/orb/_compat.py +++ b/src/orb/_compat.py @@ -173,3 +173,13 @@ class GenericModel(pydantic.BaseModel): class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ... + + +# cached properties +if TYPE_CHECKING: + cached_property = property +else: + try: + from functools import cached_property as cached_property + except ImportError: + from cached_property import cached_property as cached_property diff --git a/src/orb/resources/coupons/coupons.py b/src/orb/resources/coupons/coupons.py index f24b7d3e..22c20850 100644 --- a/src/orb/resources/coupons/coupons.py +++ b/src/orb/resources/coupons/coupons.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import Optional import httpx @@ -15,6 +15,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...pagination import SyncPage, AsyncPage @@ -29,20 +30,17 @@ make_request_options, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Coupons", "AsyncCoupons"] class Coupons(SyncAPIResource): - subscriptions: Subscriptions - with_raw_response: CouponsWithRawResponse + @cached_property + def subscriptions(self) -> Subscriptions: + return Subscriptions(self._client) - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.subscriptions = Subscriptions(client) - self.with_raw_response = CouponsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> CouponsWithRawResponse: + return CouponsWithRawResponse(self) def create( self, @@ -242,13 +240,13 @@ def fetch( class AsyncCoupons(AsyncAPIResource): - subscriptions: AsyncSubscriptions - with_raw_response: AsyncCouponsWithRawResponse + @cached_property + def subscriptions(self) -> AsyncSubscriptions: + return AsyncSubscriptions(self._client) - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.subscriptions = AsyncSubscriptions(client) - self.with_raw_response = AsyncCouponsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncCouponsWithRawResponse: + return AsyncCouponsWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/coupons/subscriptions.py b/src/orb/resources/coupons/subscriptions.py index 3afd9ad7..26d748cb 100644 --- a/src/orb/resources/coupons/subscriptions.py +++ b/src/orb/resources/coupons/subscriptions.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import Optional import httpx @@ -15,6 +15,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...pagination import SyncPage, AsyncPage @@ -24,18 +25,13 @@ ) from ...types.coupons import subscription_list_params -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Subscriptions", "AsyncSubscriptions"] class Subscriptions(SyncAPIResource): - with_raw_response: SubscriptionsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = SubscriptionsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> SubscriptionsWithRawResponse: + return SubscriptionsWithRawResponse(self) def list( self, @@ -91,11 +87,9 @@ def list( class AsyncSubscriptions(AsyncAPIResource): - with_raw_response: AsyncSubscriptionsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncSubscriptionsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncSubscriptionsWithRawResponse: + return AsyncSubscriptionsWithRawResponse(self) def list( self, diff --git a/src/orb/resources/credit_notes.py b/src/orb/resources/credit_notes.py index 1ee0b8e7..41b5c1ba 100644 --- a/src/orb/resources/credit_notes.py +++ b/src/orb/resources/credit_notes.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import Optional import httpx @@ -15,6 +15,7 @@ NotGiven, ) from .._utils import maybe_transform +from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..pagination import SyncPage, AsyncPage @@ -23,18 +24,13 @@ make_request_options, ) -if TYPE_CHECKING: - from .._client import Orb, AsyncOrb - __all__ = ["CreditNotes", "AsyncCreditNotes"] class CreditNotes(SyncAPIResource): - with_raw_response: CreditNotesWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = CreditNotesWithRawResponse(self) + @cached_property + def with_raw_response(self) -> CreditNotesWithRawResponse: + return CreditNotesWithRawResponse(self) def list( self, @@ -121,11 +117,9 @@ def fetch( class AsyncCreditNotes(AsyncAPIResource): - with_raw_response: AsyncCreditNotesWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncCreditNotesWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncCreditNotesWithRawResponse: + return AsyncCreditNotesWithRawResponse(self) def list( self, diff --git a/src/orb/resources/customers/balance_transactions.py b/src/orb/resources/customers/balance_transactions.py index 6fa9230d..772fac93 100644 --- a/src/orb/resources/customers/balance_transactions.py +++ b/src/orb/resources/customers/balance_transactions.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Union, Optional +from typing import Union, Optional from datetime import datetime from typing_extensions import Literal @@ -16,6 +16,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...pagination import SyncPage, AsyncPage @@ -30,18 +31,13 @@ balance_transaction_create_params, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["BalanceTransactions", "AsyncBalanceTransactions"] class BalanceTransactions(SyncAPIResource): - with_raw_response: BalanceTransactionsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = BalanceTransactionsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> BalanceTransactionsWithRawResponse: + return BalanceTransactionsWithRawResponse(self) def create( self, @@ -181,11 +177,9 @@ def list( class AsyncBalanceTransactions(AsyncAPIResource): - with_raw_response: AsyncBalanceTransactionsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncBalanceTransactionsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncBalanceTransactionsWithRawResponse: + return AsyncBalanceTransactionsWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/customers/costs.py b/src/orb/resources/customers/costs.py index 9fca9df8..f6f9a156 100644 --- a/src/orb/resources/customers/costs.py +++ b/src/orb/resources/customers/costs.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Union, Optional +from typing import Union, Optional from datetime import datetime from typing_extensions import Literal @@ -16,6 +16,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..._base_client import ( @@ -28,18 +29,13 @@ cost_list_by_external_id_params, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Costs", "AsyncCosts"] class Costs(SyncAPIResource): - with_raw_response: CostsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = CostsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> CostsWithRawResponse: + return CostsWithRawResponse(self) def list( self, @@ -425,11 +421,9 @@ def list_by_external_id( class AsyncCosts(AsyncAPIResource): - with_raw_response: AsyncCostsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncCostsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncCostsWithRawResponse: + return AsyncCostsWithRawResponse(self) async def list( self, diff --git a/src/orb/resources/customers/credits/credits.py b/src/orb/resources/customers/credits/credits.py index f41e3e31..5bda5d1b 100644 --- a/src/orb/resources/customers/credits/credits.py +++ b/src/orb/resources/customers/credits/credits.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import Optional import httpx @@ -15,6 +15,7 @@ NotGiven, ) from ...._utils import maybe_transform +from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ....pagination import SyncPage, AsyncPage @@ -29,20 +30,17 @@ credit_list_by_external_id_params, ) -if TYPE_CHECKING: - from ...._client import Orb, AsyncOrb - __all__ = ["Credits", "AsyncCredits"] class Credits(SyncAPIResource): - ledger: Ledger - with_raw_response: CreditsWithRawResponse + @cached_property + def ledger(self) -> Ledger: + return Ledger(self._client) - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.ledger = Ledger(client) - self.with_raw_response = CreditsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> CreditsWithRawResponse: + return CreditsWithRawResponse(self) def list( self, @@ -152,13 +150,13 @@ def list_by_external_id( class AsyncCredits(AsyncAPIResource): - ledger: AsyncLedger - with_raw_response: AsyncCreditsWithRawResponse + @cached_property + def ledger(self) -> AsyncLedger: + return AsyncLedger(self._client) - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.ledger = AsyncLedger(client) - self.with_raw_response = AsyncCreditsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncCreditsWithRawResponse: + return AsyncCreditsWithRawResponse(self) def list( self, diff --git a/src/orb/resources/customers/credits/ledger.py b/src/orb/resources/customers/credits/ledger.py index 723bf5ba..ed2999ea 100644 --- a/src/orb/resources/customers/credits/ledger.py +++ b/src/orb/resources/customers/credits/ledger.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union, Optional, cast, overload +from typing import Any, Dict, Union, Optional, cast, overload from datetime import date, datetime from typing_extensions import Literal @@ -16,6 +16,7 @@ NotGiven, ) from ...._utils import required_args, maybe_transform +from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ....pagination import SyncPage, AsyncPage @@ -34,18 +35,13 @@ ledger_create_entry_by_external_id_params, ) -if TYPE_CHECKING: - from ...._client import Orb, AsyncOrb - __all__ = ["Ledger", "AsyncLedger"] class Ledger(SyncAPIResource): - with_raw_response: LedgerWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = LedgerWithRawResponse(self) + @cached_property + def with_raw_response(self) -> LedgerWithRawResponse: + return LedgerWithRawResponse(self) def list( self, @@ -2153,11 +2149,9 @@ def list_by_external_id( class AsyncLedger(AsyncAPIResource): - with_raw_response: AsyncLedgerWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncLedgerWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncLedgerWithRawResponse: + return AsyncLedgerWithRawResponse(self) def list( self, diff --git a/src/orb/resources/customers/customers.py b/src/orb/resources/customers/customers.py index 368a6654..fa4e560b 100644 --- a/src/orb/resources/customers/customers.py +++ b/src/orb/resources/customers/customers.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Dict, List, Union, Optional +from typing import Dict, List, Union, Optional from datetime import datetime from typing_extensions import Literal @@ -27,6 +27,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...pagination import SyncPage, AsyncPage @@ -34,6 +35,7 @@ AsyncPaginator, make_request_options, ) +from .credits.credits import Credits, AsyncCredits from .balance_transactions import ( BalanceTransactions, AsyncBalanceTransactions, @@ -41,26 +43,29 @@ AsyncBalanceTransactionsWithRawResponse, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Customers", "AsyncCustomers"] class Customers(SyncAPIResource): - costs: Costs - usage: Usage - credits: Credits - balance_transactions: BalanceTransactions - with_raw_response: CustomersWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.costs = Costs(client) - self.usage = Usage(client) - self.credits = Credits(client) - self.balance_transactions = BalanceTransactions(client) - self.with_raw_response = CustomersWithRawResponse(self) + @cached_property + def costs(self) -> Costs: + return Costs(self._client) + + @cached_property + def usage(self) -> Usage: + return Usage(self._client) + + @cached_property + def credits(self) -> Credits: + return Credits(self._client) + + @cached_property + def balance_transactions(self) -> BalanceTransactions: + return BalanceTransactions(self._client) + + @cached_property + def with_raw_response(self) -> CustomersWithRawResponse: + return CustomersWithRawResponse(self) def create( self, @@ -841,19 +846,25 @@ def update_by_external_id( class AsyncCustomers(AsyncAPIResource): - costs: AsyncCosts - usage: AsyncUsage - credits: AsyncCredits - balance_transactions: AsyncBalanceTransactions - with_raw_response: AsyncCustomersWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.costs = AsyncCosts(client) - self.usage = AsyncUsage(client) - self.credits = AsyncCredits(client) - self.balance_transactions = AsyncBalanceTransactions(client) - self.with_raw_response = AsyncCustomersWithRawResponse(self) + @cached_property + def costs(self) -> AsyncCosts: + return AsyncCosts(self._client) + + @cached_property + def usage(self) -> AsyncUsage: + return AsyncUsage(self._client) + + @cached_property + def credits(self) -> AsyncCredits: + return AsyncCredits(self._client) + + @cached_property + def balance_transactions(self) -> AsyncBalanceTransactions: + return AsyncBalanceTransactions(self._client) + + @cached_property + def with_raw_response(self) -> AsyncCustomersWithRawResponse: + return AsyncCustomersWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/customers/usage.py b/src/orb/resources/customers/usage.py index 46093d4b..c8a45485 100644 --- a/src/orb/resources/customers/usage.py +++ b/src/orb/resources/customers/usage.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List, Union, Optional +from typing import List, Union, Optional from datetime import datetime import httpx @@ -15,6 +15,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..._base_client import ( @@ -27,18 +28,13 @@ usage_update_by_external_id_params, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Usage", "AsyncUsage"] class Usage(SyncAPIResource): - with_raw_response: UsageWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = UsageWithRawResponse(self) + @cached_property + def with_raw_response(self) -> UsageWithRawResponse: + return UsageWithRawResponse(self) def update( self, @@ -344,11 +340,9 @@ def update_by_external_id( class AsyncUsage(AsyncAPIResource): - with_raw_response: AsyncUsageWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncUsageWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncUsageWithRawResponse: + return AsyncUsageWithRawResponse(self) async def update( self, diff --git a/src/orb/resources/events/backfills.py b/src/orb/resources/events/backfills.py index 9dc2d171..09fdb29e 100644 --- a/src/orb/resources/events/backfills.py +++ b/src/orb/resources/events/backfills.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Union, Optional +from typing import Union, Optional from datetime import datetime import httpx @@ -15,6 +15,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...pagination import SyncPage, AsyncPage @@ -32,18 +33,13 @@ backfill_create_params, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Backfills", "AsyncBackfills"] class Backfills(SyncAPIResource): - with_raw_response: BackfillsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = BackfillsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> BackfillsWithRawResponse: + return BackfillsWithRawResponse(self) def create( self, @@ -312,11 +308,9 @@ def revert( class AsyncBackfills(AsyncAPIResource): - with_raw_response: AsyncBackfillsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncBackfillsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncBackfillsWithRawResponse: + return AsyncBackfillsWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/events/events.py b/src/orb/resources/events/events.py index 22fb1b59..912eaf71 100644 --- a/src/orb/resources/events/events.py +++ b/src/orb/resources/events/events.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List, Union, Optional +from typing import List, Union, Optional from datetime import datetime import httpx @@ -24,6 +24,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from .backfills import Backfills, AsyncBackfills, BackfillsWithRawResponse, AsyncBackfillsWithRawResponse from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper @@ -31,20 +32,17 @@ make_request_options, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Events", "AsyncEvents"] class Events(SyncAPIResource): - backfills: Backfills - with_raw_response: EventsWithRawResponse + @cached_property + def backfills(self) -> Backfills: + return Backfills(self._client) - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.backfills = Backfills(client) - self.with_raw_response = EventsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> EventsWithRawResponse: + return EventsWithRawResponse(self) def update( self, @@ -555,13 +553,13 @@ def search( class AsyncEvents(AsyncAPIResource): - backfills: AsyncBackfills - with_raw_response: AsyncEventsWithRawResponse + @cached_property + def backfills(self) -> AsyncBackfills: + return AsyncBackfills(self._client) - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.backfills = AsyncBackfills(client) - self.with_raw_response = AsyncEventsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncEventsWithRawResponse: + return AsyncEventsWithRawResponse(self) async def update( self, diff --git a/src/orb/resources/invoice_line_items.py b/src/orb/resources/invoice_line_items.py index aff533aa..13d9984d 100644 --- a/src/orb/resources/invoice_line_items.py +++ b/src/orb/resources/invoice_line_items.py @@ -2,15 +2,12 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Union +from typing import Union from datetime import date import httpx -from ..types import ( - InvoiceLineItemCreateResponse, - invoice_line_item_create_params, -) +from ..types import InvoiceLineItemCreateResponse, invoice_line_item_create_params from .._types import ( NOT_GIVEN, Body, @@ -19,24 +16,20 @@ NotGiven, ) from .._utils import maybe_transform +from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper from .._base_client import ( make_request_options, ) -if TYPE_CHECKING: - from .._client import Orb, AsyncOrb - __all__ = ["InvoiceLineItems", "AsyncInvoiceLineItems"] class InvoiceLineItems(SyncAPIResource): - with_raw_response: InvoiceLineItemsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = InvoiceLineItemsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> InvoiceLineItemsWithRawResponse: + return InvoiceLineItemsWithRawResponse(self) def create( self, @@ -109,11 +102,9 @@ def create( class AsyncInvoiceLineItems(AsyncAPIResource): - with_raw_response: AsyncInvoiceLineItemsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncInvoiceLineItemsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncInvoiceLineItemsWithRawResponse: + return AsyncInvoiceLineItemsWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/invoices.py b/src/orb/resources/invoices.py index 9298124f..bf915d2a 100644 --- a/src/orb/resources/invoices.py +++ b/src/orb/resources/invoices.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List, Union, Optional +from typing import List, Union, Optional from datetime import date, datetime from typing_extensions import Literal @@ -24,6 +24,7 @@ NotGiven, ) from .._utils import maybe_transform +from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..pagination import SyncPage, AsyncPage @@ -32,18 +33,13 @@ make_request_options, ) -if TYPE_CHECKING: - from .._client import Orb, AsyncOrb - __all__ = ["Invoices", "AsyncInvoices"] class Invoices(SyncAPIResource): - with_raw_response: InvoicesWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = InvoicesWithRawResponse(self) + @cached_property + def with_raw_response(self) -> InvoicesWithRawResponse: + return InvoicesWithRawResponse(self) def create( self, @@ -434,11 +430,9 @@ def void( class AsyncInvoices(AsyncAPIResource): - with_raw_response: AsyncInvoicesWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncInvoicesWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncInvoicesWithRawResponse: + return AsyncInvoicesWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/items.py b/src/orb/resources/items.py index 0b4d3337..5ab489bd 100644 --- a/src/orb/resources/items.py +++ b/src/orb/resources/items.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import Optional import httpx @@ -15,6 +15,7 @@ NotGiven, ) from .._utils import maybe_transform +from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..pagination import SyncPage, AsyncPage @@ -23,18 +24,13 @@ make_request_options, ) -if TYPE_CHECKING: - from .._client import Orb, AsyncOrb - __all__ = ["Items", "AsyncItems"] class Items(SyncAPIResource): - with_raw_response: ItemsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = ItemsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> ItemsWithRawResponse: + return ItemsWithRawResponse(self) def create( self, @@ -159,11 +155,9 @@ def fetch( class AsyncItems(AsyncAPIResource): - with_raw_response: AsyncItemsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncItemsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncItemsWithRawResponse: + return AsyncItemsWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/metrics.py b/src/orb/resources/metrics.py index c21bca29..6c16ddac 100644 --- a/src/orb/resources/metrics.py +++ b/src/orb/resources/metrics.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Dict, Union, Optional +from typing import Dict, Union, Optional from datetime import datetime import httpx @@ -22,6 +22,7 @@ NotGiven, ) from .._utils import maybe_transform +from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..pagination import SyncPage, AsyncPage @@ -30,18 +31,13 @@ make_request_options, ) -if TYPE_CHECKING: - from .._client import Orb, AsyncOrb - __all__ = ["Metrics", "AsyncMetrics"] class Metrics(SyncAPIResource): - with_raw_response: MetricsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = MetricsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> MetricsWithRawResponse: + return MetricsWithRawResponse(self) def create( self, @@ -203,11 +199,9 @@ def fetch( class AsyncMetrics(AsyncAPIResource): - with_raw_response: AsyncMetricsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncMetricsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncMetricsWithRawResponse: + return AsyncMetricsWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/plans/external_plan_id.py b/src/orb/resources/plans/external_plan_id.py index 8b2e6454..9cf5a4e3 100644 --- a/src/orb/resources/plans/external_plan_id.py +++ b/src/orb/resources/plans/external_plan_id.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Dict, Optional +from typing import Dict, Optional import httpx @@ -15,6 +15,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...types.plans import external_plan_id_update_params @@ -22,18 +23,13 @@ make_request_options, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["ExternalPlanID", "AsyncExternalPlanID"] class ExternalPlanID(SyncAPIResource): - with_raw_response: ExternalPlanIDWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = ExternalPlanIDWithRawResponse(self) + @cached_property + def with_raw_response(self) -> ExternalPlanIDWithRawResponse: + return ExternalPlanIDWithRawResponse(self) def update( self, @@ -145,11 +141,9 @@ def fetch( class AsyncExternalPlanID(AsyncAPIResource): - with_raw_response: AsyncExternalPlanIDWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncExternalPlanIDWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncExternalPlanIDWithRawResponse: + return AsyncExternalPlanIDWithRawResponse(self) async def update( self, diff --git a/src/orb/resources/plans/plans.py b/src/orb/resources/plans/plans.py index bb4eedd5..00187ad7 100644 --- a/src/orb/resources/plans/plans.py +++ b/src/orb/resources/plans/plans.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Dict, List, Union, Optional +from typing import Dict, List, Union, Optional from datetime import datetime from typing_extensions import Literal @@ -17,6 +17,7 @@ NotGiven, ) from ..._utils import maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...pagination import SyncPage, AsyncPage @@ -31,20 +32,17 @@ AsyncExternalPlanIDWithRawResponse, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Plans", "AsyncPlans"] class Plans(SyncAPIResource): - external_plan_id: ExternalPlanID - with_raw_response: PlansWithRawResponse + @cached_property + def external_plan_id(self) -> ExternalPlanID: + return ExternalPlanID(self._client) - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.external_plan_id = ExternalPlanID(client) - self.with_raw_response = PlansWithRawResponse(self) + @cached_property + def with_raw_response(self) -> PlansWithRawResponse: + return PlansWithRawResponse(self) def create( self, @@ -289,13 +287,13 @@ def fetch( class AsyncPlans(AsyncAPIResource): - external_plan_id: AsyncExternalPlanID - with_raw_response: AsyncPlansWithRawResponse + @cached_property + def external_plan_id(self) -> AsyncExternalPlanID: + return AsyncExternalPlanID(self._client) - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.external_plan_id = AsyncExternalPlanID(client) - self.with_raw_response = AsyncPlansWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncPlansWithRawResponse: + return AsyncPlansWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/prices/external_price_id.py b/src/orb/resources/prices/external_price_id.py index 3a2156cb..6e9ec361 100644 --- a/src/orb/resources/prices/external_price_id.py +++ b/src/orb/resources/prices/external_price_id.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, cast +from typing import Any, cast import httpx @@ -14,24 +14,20 @@ Headers, NotGiven, ) +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..._base_client import ( make_request_options, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["ExternalPriceID", "AsyncExternalPriceID"] class ExternalPriceID(SyncAPIResource): - with_raw_response: ExternalPriceIDWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = ExternalPriceIDWithRawResponse(self) + @cached_property + def with_raw_response(self) -> ExternalPriceIDWithRawResponse: + return ExternalPriceIDWithRawResponse(self) def fetch( self, @@ -72,11 +68,9 @@ def fetch( class AsyncExternalPriceID(AsyncAPIResource): - with_raw_response: AsyncExternalPriceIDWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncExternalPriceIDWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncExternalPriceIDWithRawResponse: + return AsyncExternalPriceIDWithRawResponse(self) async def fetch( self, diff --git a/src/orb/resources/prices/prices.py b/src/orb/resources/prices/prices.py index c0891663..aa732d07 100644 --- a/src/orb/resources/prices/prices.py +++ b/src/orb/resources/prices/prices.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, cast, overload +from typing import Any, Dict, Optional, cast, overload from typing_extensions import Literal import httpx @@ -16,6 +16,7 @@ NotGiven, ) from ..._utils import required_args, maybe_transform +from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ...pagination import SyncPage, AsyncPage @@ -30,20 +31,17 @@ AsyncExternalPriceIDWithRawResponse, ) -if TYPE_CHECKING: - from ..._client import Orb, AsyncOrb - __all__ = ["Prices", "AsyncPrices"] class Prices(SyncAPIResource): - external_price_id: ExternalPriceID - with_raw_response: PricesWithRawResponse + @cached_property + def external_price_id(self) -> ExternalPriceID: + return ExternalPriceID(self._client) - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.external_price_id = ExternalPriceID(client) - self.with_raw_response = PricesWithRawResponse(self) + @cached_property + def with_raw_response(self) -> PricesWithRawResponse: + return PricesWithRawResponse(self) @overload def create( @@ -1070,13 +1068,13 @@ def fetch( class AsyncPrices(AsyncAPIResource): - external_price_id: AsyncExternalPriceID - with_raw_response: AsyncPricesWithRawResponse + @cached_property + def external_price_id(self) -> AsyncExternalPriceID: + return AsyncExternalPriceID(self._client) - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.external_price_id = AsyncExternalPriceID(client) - self.with_raw_response = AsyncPricesWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncPricesWithRawResponse: + return AsyncPricesWithRawResponse(self) @overload async def create( diff --git a/src/orb/resources/subscriptions.py b/src/orb/resources/subscriptions.py index 39c80fbc..a106e328 100644 --- a/src/orb/resources/subscriptions.py +++ b/src/orb/resources/subscriptions.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Union, Optional, cast +from typing import Any, Dict, List, Union, Optional, cast from datetime import date, datetime from typing_extensions import Literal @@ -33,6 +33,7 @@ NotGiven, ) from .._utils import maybe_transform +from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..pagination import SyncPage, AsyncPage @@ -41,18 +42,13 @@ make_request_options, ) -if TYPE_CHECKING: - from .._client import Orb, AsyncOrb - __all__ = ["Subscriptions", "AsyncSubscriptions"] class Subscriptions(SyncAPIResource): - with_raw_response: SubscriptionsWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = SubscriptionsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> SubscriptionsWithRawResponse: + return SubscriptionsWithRawResponse(self) def create( self, @@ -1655,11 +1651,9 @@ def update_fixed_fee_quantity( class AsyncSubscriptions(AsyncAPIResource): - with_raw_response: AsyncSubscriptionsWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncSubscriptionsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncSubscriptionsWithRawResponse: + return AsyncSubscriptionsWithRawResponse(self) async def create( self, diff --git a/src/orb/resources/top_level.py b/src/orb/resources/top_level.py index bf599134..41ae28cc 100644 --- a/src/orb/resources/top_level.py +++ b/src/orb/resources/top_level.py @@ -2,8 +2,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING - import httpx from ..types import TopLevelPingResponse @@ -14,24 +12,20 @@ Headers, NotGiven, ) +from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper from .._base_client import ( make_request_options, ) -if TYPE_CHECKING: - from .._client import Orb, AsyncOrb - __all__ = ["TopLevel", "AsyncTopLevel"] class TopLevel(SyncAPIResource): - with_raw_response: TopLevelWithRawResponse - - def __init__(self, client: Orb) -> None: - super().__init__(client) - self.with_raw_response = TopLevelWithRawResponse(self) + @cached_property + def with_raw_response(self) -> TopLevelWithRawResponse: + return TopLevelWithRawResponse(self) def ping( self, @@ -61,11 +55,9 @@ def ping( class AsyncTopLevel(AsyncAPIResource): - with_raw_response: AsyncTopLevelWithRawResponse - - def __init__(self, client: AsyncOrb) -> None: - super().__init__(client) - self.with_raw_response = AsyncTopLevelWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncTopLevelWithRawResponse: + return AsyncTopLevelWithRawResponse(self) async def ping( self,