From d1130d99e948c720bf7e2983d47999e384e226fe Mon Sep 17 00:00:00 2001 From: joncrall Date: Sun, 26 Nov 2023 14:25:21 -0500 Subject: [PATCH] Handle deprecated coroutine --- scripts/riskeycap_full.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/scripts/riskeycap_full.py b/scripts/riskeycap_full.py index 964b817..555c272 100755 --- a/scripts/riskeycap_full.py +++ b/scripts/riskeycap_full.py @@ -63,6 +63,27 @@ SEM = asyncio.Semaphore(MAX_RUNNERS) + +if hasattr(asyncio, 'coroutine'): + from asyncio import coroutine +else: + # For compatibility with Python 3.10+ + # define the coroutine wrapper + # References: + # https://discuss.python.org/t/deprecation-of-asyncio-coroutine/4461/3 + def coroutine(fn): + import inspect + import functools + if inspect.iscoroutinefunction(fn): + return fn + + @functools.wraps(fn) + async def _wrapper(*args, **kwargs): + return fn(*args, **kwargs) + + return _wrapper + + def run_command(cmd: str) -> str: """ Run prepared behave command in shell and return its output. @@ -84,7 +105,7 @@ def run_command(cmd: str) -> str: return output -# @asyncio.coroutine +# @coroutine async def run_command_on_loop(loop: asyncio.AbstractEventLoop, command: str) -> bool: """ Run test for one particular feature, check its result and return report. @@ -99,7 +120,7 @@ async def run_command_on_loop(loop: asyncio.AbstractEventLoop, command: str) -> return output -@asyncio.coroutine +@coroutine def run_all_commands(command_list: Sequence[str] = COMMANDS) -> None: """ Run all commands in a list @@ -112,7 +133,7 @@ def run_all_commands(command_list: Sequence[str] = COMMANDS) -> None: ensure_future(process_result(result)) -@asyncio.coroutine +@coroutine def process_result(result: Any): """ Do something useful with result of the commands