Skip to content

Commit eb3d1cd

Browse files
Merge pull request #171 from maxfischer2781/maintenance/static_checks_742_v2
Fix static checks 742
2 parents 4d5cc71 + c73d463 commit eb3d1cd

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

asyncstdlib/_lrucache.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from typing import (
99
overload,
1010
Protocol,
1111
)
12+
from types import CoroutineType
1213
from typing_extensions import ParamSpec, Concatenate
1314

1415
from ._typing import AC, TypedDict
@@ -42,6 +43,12 @@ class LRUAsyncCallable(Protocol[AC]):
4243
owner: type | None = ...,
4344
) -> LRUAsyncBoundCallable[S, P, R]: ...
4445
@overload
46+
def __get__(
47+
self: LRUAsyncCallable[Callable[Concatenate[S, P], CoroutineType[Any, Any, R]]],
48+
instance: S,
49+
owner: type | None = ...,
50+
) -> LRUAsyncBoundCallable[S, P, R]: ...
51+
@overload
4552
def __get__(
4653
self: LRUAsyncCallable[Callable[Concatenate[S, P], Awaitable[R]]],
4754
instance: S,

asyncstdlib/functools.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ async def data(self):
254254
Instances on which a value is to be cached must have a
255255
``__dict__`` attribute that is a mutable mapping.
256256
"""
257-
if isinstance(type_or_getter, type) and issubclass(
257+
if iscoroutinefunction(type_or_getter):
258+
return CachedProperty(type_or_getter)
259+
elif isinstance(type_or_getter, type) and issubclass(
258260
type_or_getter, AsyncContextManager
259261
):
260262

@@ -269,14 +271,9 @@ def decorator(
269271
)
270272

271273
return decorator
272-
273-
if not iscoroutinefunction(
274-
type_or_getter # pyright: ignore[reportUnknownArgumentType]
275-
):
274+
else:
276275
raise ValueError("cached_property can only be used with a coroutine function")
277276

278-
return CachedProperty(type_or_getter)
279-
280277

281278
__REDUCE_SENTINEL = Sentinel("<no default>")
282279

0 commit comments

Comments
 (0)