Skip to content

chore: use property declarations for resource members #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions src/orb/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 14 additions & 16 deletions src/orb/resources/coupons/coupons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Optional
from typing import Optional

import httpx

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 8 additions & 14 deletions src/orb/resources/coupons/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Optional
from typing import Optional

import httpx

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 8 additions & 14 deletions src/orb/resources/credit_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Optional
from typing import Optional

import httpx

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 8 additions & 14 deletions src/orb/resources/customers/balance_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 8 additions & 14 deletions src/orb/resources/customers/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 (
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 14 additions & 16 deletions src/orb/resources/customers/credits/credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Optional
from typing import Optional

import httpx

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading