Skip to content

Commit e2dcf3e

Browse files
committed
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: #635
1 parent 52acd32 commit e2dcf3e

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

async_lru/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import dataclasses
3+
import inspect
34
import sys
45
from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined]
56
from functools import _CacheInfo, _make_key, partial, partialmethod
@@ -299,7 +300,7 @@ def wrapper(fn: _CBP[_R]) -> _LRUCacheWrapper[_R]:
299300
while isinstance(origin, (partial, partialmethod)):
300301
origin = origin.func
301302

302-
if not asyncio.iscoroutinefunction(origin):
303+
if not inspect.iscoroutinefunction(origin):
303304
raise RuntimeError(f"Coroutine function is required, got {fn!r}")
304305

305306
# functools.partialmethod support

tests/test_basic.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import inspect
23
import platform
34
import sys
45
from functools import _CacheInfo, partial
@@ -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 inspect.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 inspect.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 inspect.iscoroutinefunction(coro_wrapped)
6061

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

0 commit comments

Comments
 (0)