Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from asyncio.iscoroutinefunction to inspect. #637

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion async_lru/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
else:
from typing_extensions import Self

if sys.version_info >= (3, 14):
import inspect
iscoroutinefunction = inspect.iscoroutinefunction

Check warning on line 32 in async_lru/__init__.py

View check run for this annotation

Codecov / codecov/patch

async_lru/__init__.py#L31-L32

Added lines #L31 - L32 were not covered by tests
else:
iscoroutinefunction = asyncio.iscoroutinefunction


__version__ = "2.0.4"

Expand Down Expand Up @@ -299,7 +305,7 @@
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
Expand Down
9 changes: 5 additions & 4 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import asyncio
import inspect
import platform
import sys
from functools import _CacheInfo, partial
from typing import Callable

import pytest

from async_lru import _CacheParameters, alru_cache
from async_lru import _CacheParameters, alru_cache, iscoroutinefunction


def test_alru_cache_not_callable() -> None:
Expand All @@ -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)

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 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 iscoroutinefunction(coro_wrapped)

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

Expand Down
Loading