Skip to content

chore(internal): codegen related update #598

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
Feb 19, 2025
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
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 41
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-bdcde3824560a11eb7286deb9068127ac50ca5d2e4036d1400a8feba24f485a8.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-ca7f774eb91877a7573cadf88c8aa3c26c2e7133ba3855dbca5a434b46c762b5.yml
19 changes: 17 additions & 2 deletions src/finch/_utils/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
from typing import Any, TypeVar, Callable, Awaitable
from typing_extensions import ParamSpec

import anyio
import sniffio
import anyio.to_thread

T_Retval = TypeVar("T_Retval")
T_ParamSpec = ParamSpec("T_ParamSpec")


if sys.version_info >= (3, 9):
to_thread = asyncio.to_thread
_asyncio_to_thread = asyncio.to_thread
else:
# backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
# for Python 3.8 support
async def to_thread(
async def _asyncio_to_thread(
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
) -> Any:
"""Asynchronously run function *func* in a separate thread.
Expand All @@ -34,6 +38,17 @@ async def to_thread(
return await loop.run_in_executor(None, func_call)


async def to_thread(
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
) -> T_Retval:
if sniffio.current_async_library() == "asyncio":
return await _asyncio_to_thread(func, *args, **kwargs)

return await anyio.to_thread.run_sync(
functools.partial(func, *args, **kwargs),
)


# inspired by `asyncer`, https://github.com/tiangolo/asyncer
def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/api_resources/sandbox/test_employment.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_method_update_with_all_params(self, client: Finch) -> None:
manager={"id": "id"},
middle_name="middle_name",
source_id="source_id",
start_date="3/4/2020",
start_date="start_date",
title="title",
)
assert_matches_type(EmploymentUpdateResponse, employment, path=["response"])
Expand Down Expand Up @@ -169,7 +169,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncFinch) ->
manager={"id": "id"},
middle_name="middle_name",
source_id="source_id",
start_date="3/4/2020",
start_date="start_date",
title="title",
)
assert_matches_type(EmploymentUpdateResponse, employment, path=["response"])
Expand Down
4 changes: 2 additions & 2 deletions tests/api_resources/sandbox/test_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_method_update(self, client: Finch) -> None:
def test_method_update_with_all_params(self, client: Finch) -> None:
individual = client.sandbox.individual.update(
individual_id="individual_id",
dob="12/20/1989",
dob="dob",
emails=[
{
"data": "data",
Expand Down Expand Up @@ -108,7 +108,7 @@ async def test_method_update(self, async_client: AsyncFinch) -> None:
async def test_method_update_with_all_params(self, async_client: AsyncFinch) -> None:
individual = await async_client.sandbox.individual.update(
individual_id="individual_id",
dob="12/20/1989",
dob="dob",
emails=[
{
"data": "data",
Expand Down