diff --git a/async_lru/__init__.py b/async_lru/__init__.py index 228ebad..9b88faf 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -27,6 +27,12 @@ else: from typing_extensions import Self +if sys.version_info >= (3, 14): + import inspect + iscoroutinefunction = inspect.iscoroutinefunction +else: + iscoroutinefunction = asyncio.iscoroutinefunction + __version__ = "2.0.4" @@ -299,7 +305,7 @@ def wrapper(fn: _CBP[_R]) -> _LRUCacheWrapper[_R]: while isinstance(origin, (partial, partialmethod)): origin = origin.func - if not asyncio.iscoroutinefunction(origin): + if not 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..3898f49 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 @@ -6,7 +7,7 @@ import pytest -from async_lru import _CacheParameters, alru_cache +from async_lru import _CacheParameters, alru_cache, iscoroutinefunction def test_alru_cache_not_callable() -> None: @@ -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 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 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 iscoroutinefunction(coro_wrapped) check_lru(coro_wrapped, hits=0, misses=0, cache=0, tasks=0)