Skip to content

Commit

Permalink
Switch from asyncio.iscoroutinefunction to inspect.
Browse files Browse the repository at this point in the history
The former causes: DeprecationWarning:
'asyncio.iscoroutinefunction' is deprecated and slated for removal
in Python 3.16; use inspect.iscoroutinefunction() instead.

Fixes: aio-libs#635
  • Loading branch information
frenzymadness committed Jan 17, 2025
1 parent 52acd32 commit e2dcf3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion async_lru/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import platform
import sys
from functools import _CacheInfo, partial
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit e2dcf3e

Please sign in to comment.