diff --git a/async_lru/__init__.py b/async_lru/__init__.py index 228ebad..645872f 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -1,5 +1,6 @@ import asyncio import dataclasses +import inspect # noqa: F401 import sys from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined] from functools import _CacheInfo, _make_key, partial, partialmethod @@ -27,6 +28,11 @@ else: from typing_extensions import Self +if sys.version_info >= (3, 14): + 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/setup.cfg b/setup.cfg index b7babe0..95fde29 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,6 +74,9 @@ known_first_party=async_lru addopts= -s --keep-duplicates --cache-clear --verbose --no-cov-on-fail --cov=async_lru --cov=tests/ --cov-report=term --cov-report=html filterwarnings = error + ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio + ignore:'asyncio.set_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio + ignore:'asyncio.set_event_loop' is deprecated:DeprecationWarning:pytest_asyncio testpaths = tests/ junit_family=xunit2 asyncio_mode=auto 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)