Skip to content
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

fix: delete deprecation warning of anyio in asyncify decorator #147

Closed
wants to merge 8 commits into from
19 changes: 18 additions & 1 deletion asyncer/_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import sys
from importlib import import_module
from importlib.metadata import version as module_version
from typing import (
Any,
Awaitable,
Expand All @@ -23,6 +24,8 @@
from anyio._core._eventloop import threadlocals
from anyio.abc import TaskGroup as _TaskGroup

ANYIO_VERSION = tuple(int(num) for num in module_version("anyio").split("."))


# This was obtained with: from anyio._core._eventloop import get_asynclib
# Removed in https://github.com/agronholm/anyio/pull/429
Expand Down Expand Up @@ -358,7 +361,21 @@ def do_work(arg1, arg2, kwarg1="", kwarg2="") -> str:
and returns the result.
"""

async def wrapper(
if ANYIO_VERSION >= (4, 1, 0):

async def wrapper(
*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
) -> T_Retval:
partial_f = functools.partial(function, *args, **kwargs)
return await anyio.to_thread.run_sync(
partial_f,
abandon_on_cancel=cancellable, # type: ignore[call-arg,unused-ignore]
limiter=limiter,
)

return wrapper

async def wrapper( # type: ignore[no-redef]
*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
) -> T_Retval:
partial_f = functools.partial(function, *args, **kwargs)
Expand Down
Loading