Skip to content

Commit c2a83bb

Browse files
committed
Switch from asyncio.iscoroutinefunction to inspect for Py 3.14+.
The former causes: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead. Fixes: #635
1 parent 1e1ffdc commit c2a83bb

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

async_lru/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
else:
2828
from typing_extensions import Self
2929

30+
if sys.version_info >= (3, 14):
31+
import inspect
32+
iscoroutinefunction = inspect.iscoroutinefunction
33+
else:
34+
iscoroutinefunction = asyncio.iscoroutinefunction
35+
3036

3137
__version__ = "2.0.4"
3238

@@ -299,7 +305,7 @@ def wrapper(fn: _CBP[_R]) -> _LRUCacheWrapper[_R]:
299305
while isinstance(origin, (partial, partialmethod)):
300306
origin = origin.func
301307

302-
if not asyncio.iscoroutinefunction(origin):
308+
if not iscoroutinefunction(origin):
303309
raise RuntimeError(f"Coroutine function is required, got {fn!r}")
304310

305311
# functools.partialmethod support

tests/test_basic.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import asyncio
2+
import inspect
23
import platform
34
import sys
45
from functools import _CacheInfo, partial
56
from typing import Callable
67

78
import pytest
89

9-
from async_lru import _CacheParameters, alru_cache
10+
from async_lru import _CacheParameters, alru_cache, iscoroutinefunction
1011

1112

1213
def test_alru_cache_not_callable() -> None:
@@ -27,7 +28,7 @@ async def test_alru_cache_deco(check_lru: Callable[..., None]) -> None:
2728
async def coro() -> None:
2829
pass
2930

30-
assert asyncio.iscoroutinefunction(coro)
31+
assert iscoroutinefunction(coro)
3132

3233
check_lru(coro, hits=0, misses=0, cache=0, tasks=0)
3334

@@ -41,7 +42,7 @@ async def test_alru_cache_deco_called(check_lru: Callable[..., None]) -> None:
4142
async def coro() -> None:
4243
pass
4344

44-
assert asyncio.iscoroutinefunction(coro)
45+
assert iscoroutinefunction(coro)
4546

4647
check_lru(coro, hits=0, misses=0, cache=0, tasks=0)
4748

@@ -56,7 +57,7 @@ async def coro() -> None:
5657

5758
coro_wrapped = alru_cache(coro)
5859

59-
assert asyncio.iscoroutinefunction(coro_wrapped)
60+
assert iscoroutinefunction(coro_wrapped)
6061

6162
check_lru(coro_wrapped, hits=0, misses=0, cache=0, tasks=0)
6263

0 commit comments

Comments
 (0)