Skip to content
Merged
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
7 changes: 7 additions & 0 deletions asyncstdlib/_lrucache.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from typing import (
overload,
Protocol,
)
from types import CoroutineType
from typing_extensions import ParamSpec, Concatenate

from ._typing import AC, TypedDict
Expand Down Expand Up @@ -42,6 +43,12 @@ class LRUAsyncCallable(Protocol[AC]):
owner: type | None = ...,
) -> LRUAsyncBoundCallable[S, P, R]: ...
@overload
def __get__(
self: LRUAsyncCallable[Callable[Concatenate[S, P], CoroutineType[Any, Any, R]]],
instance: S,
owner: type | None = ...,
) -> LRUAsyncBoundCallable[S, P, R]: ...
@overload
def __get__(
self: LRUAsyncCallable[Callable[Concatenate[S, P], Awaitable[R]]],
instance: S,
Expand Down
11 changes: 4 additions & 7 deletions asyncstdlib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ async def data(self):
Instances on which a value is to be cached must have a
``__dict__`` attribute that is a mutable mapping.
"""
if isinstance(type_or_getter, type) and issubclass(
if iscoroutinefunction(type_or_getter):
return CachedProperty(type_or_getter)
elif isinstance(type_or_getter, type) and issubclass(
type_or_getter, AsyncContextManager
):

Expand All @@ -269,14 +271,9 @@ def decorator(
)

return decorator

if not iscoroutinefunction(
type_or_getter # pyright: ignore[reportUnknownArgumentType]
):
else:
raise ValueError("cached_property can only be used with a coroutine function")

return CachedProperty(type_or_getter)


__REDUCE_SENTINEL = Sentinel("<no default>")

Expand Down