asyncache
asyncache copied to clipboard
Lock type definition
Hi, reading your code I saw that you have the lock defined as AbstractContextManager
def cached(
cache: Optional[MutableMapping[_KT, Any]],
# ignoring the mypy error to be consistent with the type used
# in https://github.com/python/typeshed/tree/master/stubs/cachetools
key: Callable[..., _KT] = keys.hashkey, # type:ignore
lock: Optional["AbstractContextManager[Any]"] = None,
) -> IdentityFunction:
I think it should be AbstractAsyncContextManager because we can't do async with lock with something that is not async.
Here's an MRE
from asyncio import Lock
from asyncache import cached
from cachetools import LRUCache
@cached(cache=LRUCache(maxsize=640*1024, getsizeof=len), lock=Lock())
def get_pep(num):
...
vscode/pyright will error with:
error: Argument of type "Lock" cannot be assigned to parameter "lock" of type "AbstractContextManager[Any] | None" in function "cached"