diff --git a/async_lru/__init__.py b/async_lru/__init__.py index ecca5fdd..6da57efb 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -4,6 +4,7 @@ from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined] from functools import _CacheInfo, _make_key, partial, partialmethod from typing import ( + Any, Callable, Coroutine, Generic, @@ -208,8 +209,7 @@ async def __call__(self, /, *fn_args: _P.args, **fn_kwargs: _P.kwargs) -> _R: return cache_item.fut.result() fut = loop.create_future() - coro = self.__wrapped__(*fn_args, **fn_kwargs) - task = loop.create_task(coro) + task = loop.create_task(self.__wrapped__(*fn_args, **fn_kwargs)) self.__tasks.add(task) task.add_done_callback(partial(self._task_done_callback, fut, key)) @@ -280,7 +280,7 @@ def __init__( self.__wrapper = wrapper def cache_invalidate(self, /, *args: _P.args, **kwargs: _P.kwargs) -> bool: - return self.__wrapper.cache_invalidate(self.__instance, *args, **kwargs) + return self.__wrapper.cache_invalidate(self.__instance, *args, **kwargs) # type: ignore[arg-type] def cache_clear(self) -> None: self.__wrapper.cache_clear() @@ -296,8 +296,8 @@ def cache_info(self) -> _CacheInfo: def cache_parameters(self) -> _CacheParameters: return self.__wrapper.cache_parameters() - async def __call__(self, /, *fn_args: _P.args, **fn_kwargs: _P.kwargs) -> _R: - return await self.__wrapper(self.__instance, *fn_args, **fn_kwargs) # type: ignore[arg-type] + async def __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> _R: + return self.__wrapper.cache_invalidate(self.__instance, *args, **kwargs) # type: ignore[arg-type] def _make_wrapper( @@ -320,7 +320,10 @@ def wrapper( if hasattr(fn, "_make_unbound_method"): fn = fn._make_unbound_method() - return _LRUCacheWrapper(fn, maxsize, typed, ttl) + wrapper = _LRUCacheWrapper(fn, maxsize, typed, ttl) + if sys.version_info >= (3, 12): + wrapper = inspect.markcoroutinefunction(wrapper) + return wrapper return wrapper