Skip to content

Commit

Permalink
added type completion for main cache decorators
Browse files Browse the repository at this point in the history
DinisCruz committed Dec 31, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ba2374b commit 1f7292b
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion osbot_utils/decorators/methods/cache.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from functools import wraps
from typing import Any, Callable, TypeVar

T = TypeVar('T', bound=Callable[..., Any])

# todo: create signature based on request params so that we don't cache when the params are different
# todo: add capability to reset or change the cache value currently stored in the cache_id value
def cache(function):
def cache(function: T) -> T:
"""
Use this decorator when wanting to cache a value for all executions of the current process
"""
8 changes: 6 additions & 2 deletions osbot_utils/decorators/methods/cache_on_self.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@
from functools import wraps

from osbot_utils.utils.Misc import str_md5
from typing import Any, Callable, TypeVar

#from osbot_utils.utils.Dev import pprint

CACHE_ON_SELF_KEY_PREFIX = 'cache_on_self'
CACHE_ON_SELF_TYPES = [int, float, bytearray, bytes, bool,
@@ -14,7 +14,11 @@
# - memoryview : returns unique memory location value


def cache_on_self(function):


T = TypeVar('T', bound=Callable[..., Any]) # so that we have type hinting when using this class

def cache_on_self(function: T) -> T:
"""
Use this for cases where we want the cache to be tied to the Class instance (i.e. not global for all executions)
"""

0 comments on commit 1f7292b

Please sign in to comment.