From e2dcf3e375d4ebc3bcb51fbc3561149a4b3b801b Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Fri, 17 Jan 2025 14:57:03 +0100 Subject: [PATCH] Switch from asyncio.iscoroutinefunction to inspect. The former causes: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead. Fixes: https://github.com/aio-libs/async-lru/issues/635 --- async_lru/__init__.py | 3 ++- tests/test_basic.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/async_lru/__init__.py b/async_lru/__init__.py index 228ebad..2d10b80 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -1,5 +1,6 @@ import asyncio import dataclasses +import inspect import sys from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined] from functools import _CacheInfo, _make_key, partial, partialmethod @@ -299,7 +300,7 @@ def wrapper(fn: _CBP[_R]) -> _LRUCacheWrapper[_R]: while isinstance(origin, (partial, partialmethod)): origin = origin.func - if not asyncio.iscoroutinefunction(origin): + if not inspect.iscoroutinefunction(origin): raise RuntimeError(f"Coroutine function is required, got {fn!r}") # functools.partialmethod support diff --git a/tests/test_basic.py b/tests/test_basic.py index acc57a2..16d8e68 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,4 +1,5 @@ import asyncio +import inspect import platform import sys from functools import _CacheInfo, partial @@ -27,7 +28,7 @@ async def test_alru_cache_deco(check_lru: Callable[..., None]) -> None: async def coro() -> None: pass - assert asyncio.iscoroutinefunction(coro) + assert inspect.iscoroutinefunction(coro) check_lru(coro, hits=0, misses=0, cache=0, tasks=0) @@ -41,7 +42,7 @@ async def test_alru_cache_deco_called(check_lru: Callable[..., None]) -> None: async def coro() -> None: pass - assert asyncio.iscoroutinefunction(coro) + assert inspect.iscoroutinefunction(coro) check_lru(coro, hits=0, misses=0, cache=0, tasks=0) @@ -56,7 +57,7 @@ async def coro() -> None: coro_wrapped = alru_cache(coro) - assert asyncio.iscoroutinefunction(coro_wrapped) + assert inspect.iscoroutinefunction(coro_wrapped) check_lru(coro_wrapped, hits=0, misses=0, cache=0, tasks=0)