From ef2eb8092dea56aaa2c6b90bec59bb1d9dd06d4f Mon Sep 17 00:00:00 2001 From: Bakyt Niiazaliev Date: Thu, 25 Apr 2024 19:22:17 +0700 Subject: [PATCH 1/7] fix: delete deprecation warning of anyio --- asyncer/_main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/asyncer/_main.py b/asyncer/_main.py index 66a2413..f686549 100644 --- a/asyncer/_main.py +++ b/asyncer/_main.py @@ -1,4 +1,5 @@ import functools +from importlib.metadata import version as module_version import sys from importlib import import_module from typing import ( @@ -24,6 +25,9 @@ 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 # Released in AnyIO 4.x.x @@ -358,12 +362,22 @@ def do_work(arg1, arg2, kwarg1="", kwarg2="") -> str: and returns the result. """ + 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, limiter=limiter + ) + return wrapper + 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, cancellable=cancellable, limiter=limiter - ) + *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, cancellable=cancellable, limiter=limiter + ) return wrapper From ef09ac94dd59de62e312063db53a0f585937f46a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:27:07 +0000 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- asyncer/_main.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/asyncer/_main.py b/asyncer/_main.py index f686549..c75ce99 100644 --- a/asyncer/_main.py +++ b/asyncer/_main.py @@ -1,7 +1,7 @@ import functools -from importlib.metadata import version as module_version import sys from importlib import import_module +from importlib.metadata import version as module_version from typing import ( Any, Awaitable, @@ -24,8 +24,7 @@ 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('.')) +ANYIO_VERSION = tuple(int(num) for num in module_version("anyio").split(".")) # This was obtained with: from anyio._core._eventloop import get_asynclib @@ -363,6 +362,7 @@ def do_work(arg1, arg2, kwarg1="", kwarg2="") -> str: """ if ANYIO_VERSION >= (4, 1, 0): + async def wrapper( *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs ) -> T_Retval: @@ -370,14 +370,15 @@ async def wrapper( return await anyio.to_thread.run_sync( partial_f, abandon_on_cancel=cancellable, limiter=limiter ) + return wrapper 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, cancellable=cancellable, limiter=limiter - ) + *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, cancellable=cancellable, limiter=limiter + ) return wrapper From 41dc1415fea80a9e32b9260a4087ecb144f94baf Mon Sep 17 00:00:00 2001 From: Bakyt Niiazaliev Date: Thu, 25 Apr 2024 19:36:36 +0700 Subject: [PATCH 3/7] fix: linting code --- asyncer/_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyncer/_main.py b/asyncer/_main.py index c75ce99..aa87631 100644 --- a/asyncer/_main.py +++ b/asyncer/_main.py @@ -373,7 +373,7 @@ async def wrapper( return wrapper - async def 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) From c27c2cb0551df0d53d354f27f4d4083d823adcca Mon Sep 17 00:00:00 2001 From: Bakyt Niiazaliev Date: Thu, 25 Apr 2024 19:52:08 +0700 Subject: [PATCH 4/7] fix: unexpected-keyword on linting --- asyncer/_main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/asyncer/_main.py b/asyncer/_main.py index aa87631..dac88ee 100644 --- a/asyncer/_main.py +++ b/asyncer/_main.py @@ -368,7 +368,9 @@ async def wrapper( ) -> T_Retval: partial_f = functools.partial(function, *args, **kwargs) return await anyio.to_thread.run_sync( - partial_f, abandon_on_cancel=cancellable, limiter=limiter + partial_f, + abandon_on_cancel=cancellable, # type: ignore[call-arg] + limiter=limiter ) return wrapper From 130876901e2e1847e04aa2f28ba2f8bd39590be8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:52:24 +0000 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- asyncer/_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asyncer/_main.py b/asyncer/_main.py index dac88ee..8cdb0fc 100644 --- a/asyncer/_main.py +++ b/asyncer/_main.py @@ -369,8 +369,8 @@ async def wrapper( partial_f = functools.partial(function, *args, **kwargs) return await anyio.to_thread.run_sync( partial_f, - abandon_on_cancel=cancellable, # type: ignore[call-arg] - limiter=limiter + abandon_on_cancel=cancellable, # type: ignore[call-arg] + limiter=limiter, ) return wrapper From fe3e0fdc7bf7a5b036e3027d108ae74df9df2458 Mon Sep 17 00:00:00 2001 From: Bakyt Niiazaliev Date: Thu, 25 Apr 2024 19:56:23 +0700 Subject: [PATCH 6/7] fix: unused-ignore mypy lint error --- asyncer/_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asyncer/_main.py b/asyncer/_main.py index 8cdb0fc..e6b9f54 100644 --- a/asyncer/_main.py +++ b/asyncer/_main.py @@ -369,8 +369,8 @@ async def wrapper( partial_f = functools.partial(function, *args, **kwargs) return await anyio.to_thread.run_sync( partial_f, - abandon_on_cancel=cancellable, # type: ignore[call-arg] - limiter=limiter, + abandon_on_cancel=cancellable, # type: ignore[call-arg,unused-ignore] + limiter=limiter ) return wrapper From c828a82035b72aa81188adceb16f16a91fd06c4b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:57:56 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- asyncer/_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asyncer/_main.py b/asyncer/_main.py index e6b9f54..a6eb510 100644 --- a/asyncer/_main.py +++ b/asyncer/_main.py @@ -369,8 +369,8 @@ async def wrapper( 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 + abandon_on_cancel=cancellable, # type: ignore[call-arg,unused-ignore] + limiter=limiter, ) return wrapper