diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2437b419..dd88ece2 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "3.4.0" + ".": "3.4.1" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f32851d..d4198084 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 3.4.1 (2025-02-15) + +Full Changelog: [v3.4.0...v3.4.1](https://github.com/orbcorp/orb-python/compare/v3.4.0...v3.4.1) + +### Bug Fixes + +* asyncify on non-asyncio runtimes ([#538](https://github.com/orbcorp/orb-python/issues/538)) ([a07f92d](https://github.com/orbcorp/orb-python/commit/a07f92dacc0153fb06e800af73d1f728f41a3dbf)) + ## 3.4.0 (2025-02-14) Full Changelog: [v3.3.0...v3.4.0](https://github.com/orbcorp/orb-python/compare/v3.3.0...v3.4.0) diff --git a/pyproject.toml b/pyproject.toml index 7d09ebc8..a3b0ee9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "orb-billing" -version = "3.4.0" +version = "3.4.1" description = "The official Python library for the orb API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/orb/_utils/_sync.py b/src/orb/_utils/_sync.py index 8b3aaf2b..ad7ec71b 100644 --- a/src/orb/_utils/_sync.py +++ b/src/orb/_utils/_sync.py @@ -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. @@ -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]]: """ diff --git a/src/orb/_version.py b/src/orb/_version.py index 5046f5e5..0713e4a1 100644 --- a/src/orb/_version.py +++ b/src/orb/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "orb" -__version__ = "3.4.0" # x-release-please-version +__version__ = "3.4.1" # x-release-please-version