Skip to content

Commit 065fc91

Browse files
chore(internal): codegen related update (#598)
1 parent 9b541a6 commit 065fc91

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 41
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-bdcde3824560a11eb7286deb9068127ac50ca5d2e4036d1400a8feba24f485a8.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-ca7f774eb91877a7573cadf88c8aa3c26c2e7133ba3855dbca5a434b46c762b5.yml

src/finch/_utils/_sync.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
from typing import Any, TypeVar, Callable, Awaitable
88
from typing_extensions import ParamSpec
99

10+
import anyio
11+
import sniffio
12+
import anyio.to_thread
13+
1014
T_Retval = TypeVar("T_Retval")
1115
T_ParamSpec = ParamSpec("T_ParamSpec")
1216

1317

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

3640

41+
async def to_thread(
42+
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
43+
) -> T_Retval:
44+
if sniffio.current_async_library() == "asyncio":
45+
return await _asyncio_to_thread(func, *args, **kwargs)
46+
47+
return await anyio.to_thread.run_sync(
48+
functools.partial(func, *args, **kwargs),
49+
)
50+
51+
3752
# inspired by `asyncer`, https://github.com/tiangolo/asyncer
3853
def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
3954
"""

tests/api_resources/sandbox/test_employment.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_method_update_with_all_params(self, client: Finch) -> None:
7373
manager={"id": "id"},
7474
middle_name="middle_name",
7575
source_id="source_id",
76-
start_date="3/4/2020",
76+
start_date="start_date",
7777
title="title",
7878
)
7979
assert_matches_type(EmploymentUpdateResponse, employment, path=["response"])
@@ -169,7 +169,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncFinch) ->
169169
manager={"id": "id"},
170170
middle_name="middle_name",
171171
source_id="source_id",
172-
start_date="3/4/2020",
172+
start_date="start_date",
173173
title="title",
174174
)
175175
assert_matches_type(EmploymentUpdateResponse, employment, path=["response"])

tests/api_resources/sandbox/test_individual.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_method_update(self, client: Finch) -> None:
2828
def test_method_update_with_all_params(self, client: Finch) -> None:
2929
individual = client.sandbox.individual.update(
3030
individual_id="individual_id",
31-
dob="12/20/1989",
31+
dob="dob",
3232
emails=[
3333
{
3434
"data": "data",
@@ -108,7 +108,7 @@ async def test_method_update(self, async_client: AsyncFinch) -> None:
108108
async def test_method_update_with_all_params(self, async_client: AsyncFinch) -> None:
109109
individual = await async_client.sandbox.individual.update(
110110
individual_id="individual_id",
111-
dob="12/20/1989",
111+
dob="dob",
112112
emails=[
113113
{
114114
"data": "data",

0 commit comments

Comments
 (0)