Skip to content

chore: use property declarations for resource members #247

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/finch/_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
22 changes: 7 additions & 15 deletions src/finch/resources/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from typing import TYPE_CHECKING

import httpx

from ..types import Introspection, DisconnectResponse
Expand All @@ -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 Finch, AsyncFinch

__all__ = ["Account", "AsyncAccount"]


class Account(SyncAPIResource):
with_raw_response: AccountWithRawResponse

def __init__(self, client: Finch) -> None:
super().__init__(client)
self.with_raw_response = AccountWithRawResponse(self)
@cached_property
def with_raw_response(self) -> AccountWithRawResponse:
return AccountWithRawResponse(self)

def disconnect(
self,
Expand Down Expand Up @@ -77,11 +71,9 @@ def introspect(


class AsyncAccount(AsyncAPIResource):
with_raw_response: AsyncAccountWithRawResponse

def __init__(self, client: AsyncFinch) -> None:
super().__init__(client)
self.with_raw_response = AsyncAccountWithRawResponse(self)
@cached_property
def with_raw_response(self) -> AsyncAccountWithRawResponse:
return AsyncAccountWithRawResponse(self)

async def disconnect(
self,
Expand Down
30 changes: 14 additions & 16 deletions src/finch/resources/hris/benefits/benefits.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 @@ -14,6 +14,7 @@
NotGiven,
)
from ...._utils import maybe_transform
from ...._compat import cached_property
from .individuals import Individuals, AsyncIndividuals, IndividualsWithRawResponse, AsyncIndividualsWithRawResponse
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_raw_response_wrapper, async_to_raw_response_wrapper
Expand All @@ -33,20 +34,17 @@
make_request_options,
)

if TYPE_CHECKING:
from ...._client import Finch, AsyncFinch

__all__ = ["Benefits", "AsyncBenefits"]


class Benefits(SyncAPIResource):
individuals: Individuals
with_raw_response: BenefitsWithRawResponse
@cached_property
def individuals(self) -> Individuals:
return Individuals(self._client)

def __init__(self, client: Finch) -> None:
super().__init__(client)
self.individuals = Individuals(client)
self.with_raw_response = BenefitsWithRawResponse(self)
@cached_property
def with_raw_response(self) -> BenefitsWithRawResponse:
return BenefitsWithRawResponse(self)

def create(
self,
Expand Down Expand Up @@ -215,13 +213,13 @@ def list_supported_benefits(


class AsyncBenefits(AsyncAPIResource):
individuals: AsyncIndividuals
with_raw_response: AsyncBenefitsWithRawResponse
@cached_property
def individuals(self) -> AsyncIndividuals:
return AsyncIndividuals(self._client)

def __init__(self, client: AsyncFinch) -> None:
super().__init__(client)
self.individuals = AsyncIndividuals(client)
self.with_raw_response = AsyncBenefitsWithRawResponse(self)
@cached_property
def with_raw_response(self) -> AsyncBenefitsWithRawResponse:
return AsyncBenefitsWithRawResponse(self)

async def create(
self,
Expand Down
22 changes: 8 additions & 14 deletions src/finch/resources/hris/benefits/individuals.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, List
from typing import List

import httpx

Expand All @@ -14,6 +14,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 SyncSinglePage, AsyncSinglePage
Expand All @@ -31,18 +32,13 @@
individual_retrieve_many_benefits_params,
)

if TYPE_CHECKING:
from ...._client import Finch, AsyncFinch

__all__ = ["Individuals", "AsyncIndividuals"]


class Individuals(SyncAPIResource):
with_raw_response: IndividualsWithRawResponse

def __init__(self, client: Finch) -> None:
super().__init__(client)
self.with_raw_response = IndividualsWithRawResponse(self)
@cached_property
def with_raw_response(self) -> IndividualsWithRawResponse:
return IndividualsWithRawResponse(self)

def enroll_many(
self,
Expand Down Expand Up @@ -211,11 +207,9 @@ def unenroll_many(


class AsyncIndividuals(AsyncAPIResource):
with_raw_response: AsyncIndividualsWithRawResponse

def __init__(self, client: AsyncFinch) -> None:
super().__init__(client)
self.with_raw_response = AsyncIndividualsWithRawResponse(self)
@cached_property
def with_raw_response(self) -> AsyncIndividualsWithRawResponse:
return AsyncIndividualsWithRawResponse(self)

def enroll_many(
self,
Expand Down
22 changes: 7 additions & 15 deletions src/finch/resources/hris/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from typing import TYPE_CHECKING

import httpx

from ..._types import (
Expand All @@ -13,25 +11,21 @@
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 ...types.hris import Company
from ..._base_client import (
make_request_options,
)

if TYPE_CHECKING:
from ..._client import Finch, AsyncFinch

__all__ = ["CompanyResource", "AsyncCompanyResource"]


class CompanyResource(SyncAPIResource):
with_raw_response: CompanyResourceWithRawResponse

def __init__(self, client: Finch) -> None:
super().__init__(client)
self.with_raw_response = CompanyResourceWithRawResponse(self)
@cached_property
def with_raw_response(self) -> CompanyResourceWithRawResponse:
return CompanyResourceWithRawResponse(self)

def retrieve(
self,
Expand All @@ -54,11 +48,9 @@ def retrieve(


class AsyncCompanyResource(AsyncAPIResource):
with_raw_response: AsyncCompanyResourceWithRawResponse

def __init__(self, client: AsyncFinch) -> None:
super().__init__(client)
self.with_raw_response = AsyncCompanyResourceWithRawResponse(self)
@cached_property
def with_raw_response(self) -> AsyncCompanyResourceWithRawResponse:
return AsyncCompanyResourceWithRawResponse(self)

async def retrieve(
self,
Expand Down
26 changes: 8 additions & 18 deletions src/finch/resources/hris/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import typing_extensions
from typing import TYPE_CHECKING

import httpx

Expand All @@ -15,30 +14,23 @@
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 SyncIndividualsPage, AsyncIndividualsPage
from ...types.hris import (
IndividualInDirectory,
directory_list_params,
)
from ...types.hris import IndividualInDirectory, directory_list_params
from ..._base_client import (
AsyncPaginator,
make_request_options,
)

if TYPE_CHECKING:
from ..._client import Finch, AsyncFinch

__all__ = ["Directory", "AsyncDirectory"]


class Directory(SyncAPIResource):
with_raw_response: DirectoryWithRawResponse

def __init__(self, client: Finch) -> None:
super().__init__(client)
self.with_raw_response = DirectoryWithRawResponse(self)
@cached_property
def with_raw_response(self) -> DirectoryWithRawResponse:
return DirectoryWithRawResponse(self)

def list(
self,
Expand Down Expand Up @@ -127,11 +119,9 @@ def list_individuals(


class AsyncDirectory(AsyncAPIResource):
with_raw_response: AsyncDirectoryWithRawResponse

def __init__(self, client: AsyncFinch) -> None:
super().__init__(client)
self.with_raw_response = AsyncDirectoryWithRawResponse(self)
@cached_property
def with_raw_response(self) -> AsyncDirectoryWithRawResponse:
return AsyncDirectoryWithRawResponse(self)

def list(
self,
Expand Down
22 changes: 8 additions & 14 deletions src/finch/resources/hris/employments.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, List
from typing import List

import httpx

Expand All @@ -14,6 +14,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 SyncResponsesPage, AsyncResponsesPage
Expand All @@ -23,18 +24,13 @@
make_request_options,
)

if TYPE_CHECKING:
from ..._client import Finch, AsyncFinch

__all__ = ["Employments", "AsyncEmployments"]


class Employments(SyncAPIResource):
with_raw_response: EmploymentsWithRawResponse

def __init__(self, client: Finch) -> None:
super().__init__(client)
self.with_raw_response = EmploymentsWithRawResponse(self)
@cached_property
def with_raw_response(self) -> EmploymentsWithRawResponse:
return EmploymentsWithRawResponse(self)

def retrieve_many(
self,
Expand Down Expand Up @@ -78,11 +74,9 @@ def retrieve_many(


class AsyncEmployments(AsyncAPIResource):
with_raw_response: AsyncEmploymentsWithRawResponse

def __init__(self, client: AsyncFinch) -> None:
super().__init__(client)
self.with_raw_response = AsyncEmploymentsWithRawResponse(self)
@cached_property
def with_raw_response(self) -> AsyncEmploymentsWithRawResponse:
return AsyncEmploymentsWithRawResponse(self)

def retrieve_many(
self,
Expand Down
Loading