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

ADDED: typing to cached.__call__ #880

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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: 6 additions & 2 deletions aiocache/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import functools
import inspect
import logging
from typing import Any, Awaitable, Callable, ParamSpec, TypeVar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to use typing_extensions to support older versions of python.


from aiocache.base import SENTINEL
from aiocache.factory import Cache, caches
from aiocache.lock import RedLock

logger = logging.getLogger(__name__)

P = ParamSpec("P")
T = TypeVar("T", bound=Any)


class cached:
"""
Expand Down Expand Up @@ -83,7 +87,7 @@ def __init__(
self._plugins = plugins
self._kwargs = kwargs

def __call__(self, f):
def __call__(self, f: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
if self.alias:
self.cache = caches.get(self.alias)
for arg in ("serializer", "namespace", "plugins"):
Expand All @@ -99,7 +103,7 @@ def __call__(self, f):
)

@functools.wraps(f)
async def wrapper(*args, **kwargs):
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
return await self.decorator(f, *args, **kwargs)

wrapper.cache = self.cache
Expand Down