From 7769bebf4dd5063b37ba43dc1736b5e029a0cd7d 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/finch/_compat.py | 10 ++ src/finch/resources/account.py | 22 ++-- src/finch/resources/hris/benefits/benefits.py | 30 +++-- .../resources/hris/benefits/individuals.py | 22 ++-- src/finch/resources/hris/company.py | 22 ++-- src/finch/resources/hris/directory.py | 26 ++--- src/finch/resources/hris/employments.py | 22 ++-- src/finch/resources/hris/hris.py | 107 +++++++++++------- src/finch/resources/hris/individuals.py | 22 ++-- src/finch/resources/hris/pay_statements.py | 22 ++-- src/finch/resources/hris/payments.py | 22 ++-- src/finch/resources/jobs/automated.py | 28 ++--- src/finch/resources/jobs/jobs.py | 44 +++---- src/finch/resources/jobs/manual.py | 22 ++-- src/finch/resources/providers.py | 22 ++-- src/finch/resources/request_forwarding.py | 27 ++--- src/finch/resources/webhooks.py | 10 -- 18 files changed, 204 insertions(+), 277 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a422005e..96698a08 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/finch/_compat.py b/src/finch/_compat.py index d95db8ed..3cda3990 100644 --- a/src/finch/_compat.py +++ b/src/finch/_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/finch/resources/account.py b/src/finch/resources/account.py index 0cb7b3aa..857bb14a 100644 --- a/src/finch/resources/account.py +++ b/src/finch/resources/account.py @@ -2,8 +2,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING - import httpx from ..types import Introspection, DisconnectResponse @@ -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, @@ -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, diff --git a/src/finch/resources/hris/benefits/benefits.py b/src/finch/resources/hris/benefits/benefits.py index 4752a838..575c9d2d 100644 --- a/src/finch/resources/hris/benefits/benefits.py +++ b/src/finch/resources/hris/benefits/benefits.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import Optional import httpx @@ -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 @@ -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, @@ -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, diff --git a/src/finch/resources/hris/benefits/individuals.py b/src/finch/resources/hris/benefits/individuals.py index cb09ddf4..cf978066 100644 --- a/src/finch/resources/hris/benefits/individuals.py +++ b/src/finch/resources/hris/benefits/individuals.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List +from typing import List import httpx @@ -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 @@ -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, @@ -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, diff --git a/src/finch/resources/hris/company.py b/src/finch/resources/hris/company.py index 3ee67da7..b4f4ac9e 100644 --- a/src/finch/resources/hris/company.py +++ b/src/finch/resources/hris/company.py @@ -2,8 +2,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING - import httpx from ..._types import ( @@ -13,6 +11,7 @@ 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 @@ -20,18 +19,13 @@ 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, @@ -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, diff --git a/src/finch/resources/hris/directory.py b/src/finch/resources/hris/directory.py index 221586f6..01f169de 100644 --- a/src/finch/resources/hris/directory.py +++ b/src/finch/resources/hris/directory.py @@ -3,7 +3,6 @@ from __future__ import annotations import typing_extensions -from typing import TYPE_CHECKING import httpx @@ -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, @@ -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, diff --git a/src/finch/resources/hris/employments.py b/src/finch/resources/hris/employments.py index c0bd79ba..6330de09 100644 --- a/src/finch/resources/hris/employments.py +++ b/src/finch/resources/hris/employments.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List +from typing import List import httpx @@ -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 @@ -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, @@ -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, diff --git a/src/finch/resources/hris/hris.py b/src/finch/resources/hris/hris.py index 0ba66160..e02ebae1 100644 --- a/src/finch/resources/hris/hris.py +++ b/src/finch/resources/hris/hris.py @@ -2,8 +2,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING - from .company import ( CompanyResource, AsyncCompanyResource, @@ -12,6 +10,7 @@ ) from .benefits import Benefits, AsyncBenefits, BenefitsWithRawResponse, AsyncBenefitsWithRawResponse from .payments import Payments, AsyncPayments, PaymentsWithRawResponse, AsyncPaymentsWithRawResponse +from ..._compat import cached_property from .directory import Directory, AsyncDirectory, DirectoryWithRawResponse, AsyncDirectoryWithRawResponse from ..._resource import SyncAPIResource, AsyncAPIResource from .employments import Employments, AsyncEmployments, EmploymentsWithRawResponse, AsyncEmploymentsWithRawResponse @@ -22,55 +21,77 @@ PayStatementsWithRawResponse, AsyncPayStatementsWithRawResponse, ) - -if TYPE_CHECKING: - from ..._client import Finch, AsyncFinch +from .benefits.benefits import Benefits, AsyncBenefits __all__ = ["HRIS", "AsyncHRIS"] class HRIS(SyncAPIResource): - company: CompanyResource - directory: Directory - individuals: Individuals - employments: Employments - payments: Payments - pay_statements: PayStatements - benefits: Benefits - with_raw_response: HRISWithRawResponse - - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.company = CompanyResource(client) - self.directory = Directory(client) - self.individuals = Individuals(client) - self.employments = Employments(client) - self.payments = Payments(client) - self.pay_statements = PayStatements(client) - self.benefits = Benefits(client) - self.with_raw_response = HRISWithRawResponse(self) + @cached_property + def company(self) -> CompanyResource: + return CompanyResource(self._client) + + @cached_property + def directory(self) -> Directory: + return Directory(self._client) + + @cached_property + def individuals(self) -> Individuals: + return Individuals(self._client) + + @cached_property + def employments(self) -> Employments: + return Employments(self._client) + + @cached_property + def payments(self) -> Payments: + return Payments(self._client) + + @cached_property + def pay_statements(self) -> PayStatements: + return PayStatements(self._client) + + @cached_property + def benefits(self) -> Benefits: + return Benefits(self._client) + + @cached_property + def with_raw_response(self) -> HRISWithRawResponse: + return HRISWithRawResponse(self) class AsyncHRIS(AsyncAPIResource): - company: AsyncCompanyResource - directory: AsyncDirectory - individuals: AsyncIndividuals - employments: AsyncEmployments - payments: AsyncPayments - pay_statements: AsyncPayStatements - benefits: AsyncBenefits - with_raw_response: AsyncHRISWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.company = AsyncCompanyResource(client) - self.directory = AsyncDirectory(client) - self.individuals = AsyncIndividuals(client) - self.employments = AsyncEmployments(client) - self.payments = AsyncPayments(client) - self.pay_statements = AsyncPayStatements(client) - self.benefits = AsyncBenefits(client) - self.with_raw_response = AsyncHRISWithRawResponse(self) + @cached_property + def company(self) -> AsyncCompanyResource: + return AsyncCompanyResource(self._client) + + @cached_property + def directory(self) -> AsyncDirectory: + return AsyncDirectory(self._client) + + @cached_property + def individuals(self) -> AsyncIndividuals: + return AsyncIndividuals(self._client) + + @cached_property + def employments(self) -> AsyncEmployments: + return AsyncEmployments(self._client) + + @cached_property + def payments(self) -> AsyncPayments: + return AsyncPayments(self._client) + + @cached_property + def pay_statements(self) -> AsyncPayStatements: + return AsyncPayStatements(self._client) + + @cached_property + def benefits(self) -> AsyncBenefits: + return AsyncBenefits(self._client) + + @cached_property + def with_raw_response(self) -> AsyncHRISWithRawResponse: + return AsyncHRISWithRawResponse(self) class HRISWithRawResponse: diff --git a/src/finch/resources/hris/individuals.py b/src/finch/resources/hris/individuals.py index 8ca24125..ced03825 100644 --- a/src/finch/resources/hris/individuals.py +++ b/src/finch/resources/hris/individuals.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List, Optional +from typing import List, Optional import httpx @@ -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 @@ -23,18 +24,13 @@ make_request_options, ) -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 retrieve_many( self, @@ -79,11 +75,9 @@ def retrieve_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 retrieve_many( self, diff --git a/src/finch/resources/hris/pay_statements.py b/src/finch/resources/hris/pay_statements.py index 6ad4be76..4d0a4730 100644 --- a/src/finch/resources/hris/pay_statements.py +++ b/src/finch/resources/hris/pay_statements.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List +from typing import List import httpx @@ -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 @@ -23,18 +24,13 @@ make_request_options, ) -if TYPE_CHECKING: - from ..._client import Finch, AsyncFinch - __all__ = ["PayStatements", "AsyncPayStatements"] class PayStatements(SyncAPIResource): - with_raw_response: PayStatementsWithRawResponse - - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.with_raw_response = PayStatementsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> PayStatementsWithRawResponse: + return PayStatementsWithRawResponse(self) def retrieve_many( self, @@ -79,11 +75,9 @@ def retrieve_many( class AsyncPayStatements(AsyncAPIResource): - with_raw_response: AsyncPayStatementsWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.with_raw_response = AsyncPayStatementsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncPayStatementsWithRawResponse: + return AsyncPayStatementsWithRawResponse(self) def retrieve_many( self, diff --git a/src/finch/resources/hris/payments.py b/src/finch/resources/hris/payments.py index d5d0b28d..f05b36d6 100644 --- a/src/finch/resources/hris/payments.py +++ b/src/finch/resources/hris/payments.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Union +from typing import Union from datetime import date 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 SyncSinglePage, AsyncSinglePage @@ -24,18 +25,13 @@ make_request_options, ) -if TYPE_CHECKING: - from ..._client import Finch, AsyncFinch - __all__ = ["Payments", "AsyncPayments"] class Payments(SyncAPIResource): - with_raw_response: PaymentsWithRawResponse - - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.with_raw_response = PaymentsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> PaymentsWithRawResponse: + return PaymentsWithRawResponse(self) def list( self, @@ -88,11 +84,9 @@ def list( class AsyncPayments(AsyncAPIResource): - with_raw_response: AsyncPaymentsWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.with_raw_response = AsyncPaymentsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncPaymentsWithRawResponse: + return AsyncPaymentsWithRawResponse(self) def list( self, diff --git a/src/finch/resources/jobs/automated.py b/src/finch/resources/jobs/automated.py index 48f2199b..54a77f09 100644 --- a/src/finch/resources/jobs/automated.py +++ b/src/finch/resources/jobs/automated.py @@ -2,7 +2,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING from typing_extensions import Literal import httpx @@ -15,32 +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 SyncPage, AsyncPage -from ...types.jobs import ( - AutomatedAsyncJob, - AutomatedCreateResponse, - automated_list_params, - automated_create_params, -) +from ...types.jobs import AutomatedAsyncJob, AutomatedCreateResponse, automated_list_params, automated_create_params from ..._base_client import ( AsyncPaginator, make_request_options, ) -if TYPE_CHECKING: - from ..._client import Finch, AsyncFinch - __all__ = ["Automated", "AsyncAutomated"] class Automated(SyncAPIResource): - with_raw_response: AutomatedWithRawResponse - - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.with_raw_response = AutomatedWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AutomatedWithRawResponse: + return AutomatedWithRawResponse(self) def create( self, @@ -169,11 +159,9 @@ def list( class AsyncAutomated(AsyncAPIResource): - with_raw_response: AsyncAutomatedWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.with_raw_response = AsyncAutomatedWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncAutomatedWithRawResponse: + return AsyncAutomatedWithRawResponse(self) async def create( self, diff --git a/src/finch/resources/jobs/jobs.py b/src/finch/resources/jobs/jobs.py index a47c4ddd..314cd630 100644 --- a/src/finch/resources/jobs/jobs.py +++ b/src/finch/resources/jobs/jobs.py @@ -2,40 +2,40 @@ from __future__ import annotations -from typing import TYPE_CHECKING - from .manual import Manual, AsyncManual, ManualWithRawResponse, AsyncManualWithRawResponse +from ..._compat import cached_property from .automated import Automated, AsyncAutomated, AutomatedWithRawResponse, AsyncAutomatedWithRawResponse from ..._resource import SyncAPIResource, AsyncAPIResource -if TYPE_CHECKING: - from ..._client import Finch, AsyncFinch - __all__ = ["Jobs", "AsyncJobs"] class Jobs(SyncAPIResource): - automated: Automated - manual: Manual - with_raw_response: JobsWithRawResponse + @cached_property + def automated(self) -> Automated: + return Automated(self._client) + + @cached_property + def manual(self) -> Manual: + return Manual(self._client) - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.automated = Automated(client) - self.manual = Manual(client) - self.with_raw_response = JobsWithRawResponse(self) + @cached_property + def with_raw_response(self) -> JobsWithRawResponse: + return JobsWithRawResponse(self) class AsyncJobs(AsyncAPIResource): - automated: AsyncAutomated - manual: AsyncManual - with_raw_response: AsyncJobsWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.automated = AsyncAutomated(client) - self.manual = AsyncManual(client) - self.with_raw_response = AsyncJobsWithRawResponse(self) + @cached_property + def automated(self) -> AsyncAutomated: + return AsyncAutomated(self._client) + + @cached_property + def manual(self) -> AsyncManual: + return AsyncManual(self._client) + + @cached_property + def with_raw_response(self) -> AsyncJobsWithRawResponse: + return AsyncJobsWithRawResponse(self) class JobsWithRawResponse: diff --git a/src/finch/resources/jobs/manual.py b/src/finch/resources/jobs/manual.py index 61f16619..aa613e92 100644 --- a/src/finch/resources/jobs/manual.py +++ b/src/finch/resources/jobs/manual.py @@ -2,8 +2,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING - import httpx from ..._types import ( @@ -13,6 +11,7 @@ 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.jobs import ManualAsyncJob @@ -20,18 +19,13 @@ make_request_options, ) -if TYPE_CHECKING: - from ..._client import Finch, AsyncFinch - __all__ = ["Manual", "AsyncManual"] class Manual(SyncAPIResource): - with_raw_response: ManualWithRawResponse - - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.with_raw_response = ManualWithRawResponse(self) + @cached_property + def with_raw_response(self) -> ManualWithRawResponse: + return ManualWithRawResponse(self) def retrieve( self, @@ -68,11 +62,9 @@ def retrieve( class AsyncManual(AsyncAPIResource): - with_raw_response: AsyncManualWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.with_raw_response = AsyncManualWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncManualWithRawResponse: + return AsyncManualWithRawResponse(self) async def retrieve( self, diff --git a/src/finch/resources/providers.py b/src/finch/resources/providers.py index 5f8b17c7..f2ff34c8 100644 --- a/src/finch/resources/providers.py +++ b/src/finch/resources/providers.py @@ -2,8 +2,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING - import httpx from ..types import Provider @@ -14,6 +12,7 @@ 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 ..pagination import SyncSinglePage, AsyncSinglePage @@ -22,18 +21,13 @@ make_request_options, ) -if TYPE_CHECKING: - from .._client import Finch, AsyncFinch - __all__ = ["Providers", "AsyncProviders"] class Providers(SyncAPIResource): - with_raw_response: ProvidersWithRawResponse - - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.with_raw_response = ProvidersWithRawResponse(self) + @cached_property + def with_raw_response(self) -> ProvidersWithRawResponse: + return ProvidersWithRawResponse(self) def list( self, @@ -57,11 +51,9 @@ def list( class AsyncProviders(AsyncAPIResource): - with_raw_response: AsyncProvidersWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.with_raw_response = AsyncProvidersWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncProvidersWithRawResponse: + return AsyncProvidersWithRawResponse(self) def list( self, diff --git a/src/finch/resources/request_forwarding.py b/src/finch/resources/request_forwarding.py index 4c571b39..256481b6 100644 --- a/src/finch/resources/request_forwarding.py +++ b/src/finch/resources/request_forwarding.py @@ -2,14 +2,11 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import Optional import httpx -from ..types import ( - RequestForwardingForwardResponse, - request_forwarding_forward_params, -) +from ..types import RequestForwardingForwardResponse, request_forwarding_forward_params from .._types import ( NOT_GIVEN, Body, @@ -18,24 +15,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 Finch, AsyncFinch - __all__ = ["RequestForwarding", "AsyncRequestForwarding"] class RequestForwarding(SyncAPIResource): - with_raw_response: RequestForwardingWithRawResponse - - def __init__(self, client: Finch) -> None: - super().__init__(client) - self.with_raw_response = RequestForwardingWithRawResponse(self) + @cached_property + def with_raw_response(self) -> RequestForwardingWithRawResponse: + return RequestForwardingWithRawResponse(self) def forward( self, @@ -105,11 +98,9 @@ def forward( class AsyncRequestForwarding(AsyncAPIResource): - with_raw_response: AsyncRequestForwardingWithRawResponse - - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - self.with_raw_response = AsyncRequestForwardingWithRawResponse(self) + @cached_property + def with_raw_response(self) -> AsyncRequestForwardingWithRawResponse: + return AsyncRequestForwardingWithRawResponse(self) async def forward( self, diff --git a/src/finch/resources/webhooks.py b/src/finch/resources/webhooks.py index 28d7ace6..6d68645f 100644 --- a/src/finch/resources/webhooks.py +++ b/src/finch/resources/webhooks.py @@ -7,7 +7,6 @@ import math import base64 import hashlib -from typing import TYPE_CHECKING from datetime import datetime, timezone, timedelta from .._types import ( @@ -18,16 +17,10 @@ ) from .._resource import SyncAPIResource, AsyncAPIResource -if TYPE_CHECKING: - from .._client import Finch, AsyncFinch - __all__ = ["Webhooks", "AsyncWebhooks"] class Webhooks(SyncAPIResource): - def __init__(self, client: Finch) -> None: - super().__init__(client) - def unwrap( self, payload: str | bytes, @@ -121,9 +114,6 @@ def verify_signature( class AsyncWebhooks(AsyncAPIResource): - def __init__(self, client: AsyncFinch) -> None: - super().__init__(client) - def unwrap( self, payload: str | bytes,