Contributed stubs for cachetools package (#4422)

Co-authored-by: Eric Traut <erictr@microsoft.com>
Co-authored-by: hauntsaninja <>
This commit is contained in:
Eric Traut
2020-08-10 13:34:22 -07:00
committed by GitHub
parent 224da619f5
commit 9a4df32d86
9 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
from .cache import Cache as Cache
from .decorators import cached as cached, cachedmethod as cachedmethod
from .lfu import LFUCache as LFUCache
from .lru import LRUCache as LRUCache
from .rr import RRCache as RRCache
from .ttl import TTLCache as TTLCache

7
third_party/2and3/cachetools/abc.pyi vendored Normal file
View File

@@ -0,0 +1,7 @@
from abc import ABCMeta
from typing import MutableMapping, TypeVar
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
class DefaultMapping(MutableMapping[_KT, _VT], metaclass=ABCMeta): ...

20
third_party/2and3/cachetools/cache.pyi vendored Normal file
View File

@@ -0,0 +1,20 @@
from typing import Callable, Generic, Iterator, Optional, TypeVar
from .abc import DefaultMapping as DefaultMapping
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
class Cache(DefaultMapping[_KT, _VT], Generic[_KT, _VT]):
def __init__(self, maxsize: int, getsizeof: Optional[Callable[[_VT], int]] = ...) -> None: ...
def __getitem__(self, key: _KT) -> _VT: ...
def __setitem__(self, key: _KT, value: _VT) -> None: ...
def __delitem__(self, key: _KT) -> None: ...
def __iter__(self) -> Iterator[_KT]: ...
def __len__(self) -> int: ...
@property
def maxsize(self) -> int: ...
@property
def currsize(self) -> int: ...
@staticmethod
def getsizeof(value: _VT) -> int: ...

View File

@@ -0,0 +1,11 @@
from typing import Any, Callable, ContextManager, Optional, TypeVar
from .cache import Cache
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
_T = TypeVar("_T", bound=Callable[..., Any])
_T_co = TypeVar("_T_co", covariant=True)
def cached(cache: Cache[_KT, _VT], key: _KT = ..., lock: Optional[ContextManager[_T_co]] = ...) -> Callable[[_T], _T]: ...
def cachedmethod(cache: Cache[_KT, _VT], key: _KT = ..., lock: Optional[ContextManager[_T_co]] = ...) -> Callable[[_T], _T]: ...

8
third_party/2and3/cachetools/func.pyi vendored Normal file
View File

@@ -0,0 +1,8 @@
from typing import Callable, Optional, Sequence, TypeVar
_T = TypeVar("_T")
def lfu_cache(maxsize: int = ..., typed: bool = ...) -> None: ...
def lru_cache(maxsize: int = ..., typed: bool = ...) -> None: ...
def rr_cache(maxsize: int = ..., choice: Optional[Callable[[Sequence[_T]], _T]] = ..., typed: bool = ...) -> None: ...
def ttl_cache(maxsize: int = ..., ttl: int = ..., timer: float = ..., typed: bool = ...) -> None: ...

14
third_party/2and3/cachetools/lfu.pyi vendored Normal file
View File

@@ -0,0 +1,14 @@
from typing import Callable, Iterator, Optional, TypeVar
from .cache import Cache
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
class LFUCache(Cache[_KT, _VT]):
def __init__(self, maxsize: int, getsizeof: Optional[Callable[[_VT], int]] = ...) -> None: ...
def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ...
def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ...
def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ...
def __iter__(self) -> Iterator[_KT]: ...
def __len__(self) -> int: ...

13
third_party/2and3/cachetools/lru.pyi vendored Normal file
View File

@@ -0,0 +1,13 @@
from typing import Callable, Iterator, Optional, TypeVar
from .cache import Cache as Cache
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
class LRUCache(Cache[_KT, _VT]):
def __init__(self, maxsize: int, getsizeof: Optional[Callable[[_VT], int]] = ...) -> None: ...
def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ...
def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ...
def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ...
def __iter__(self) -> Iterator[_KT]: ...

21
third_party/2and3/cachetools/rr.pyi vendored Normal file
View File

@@ -0,0 +1,21 @@
from typing import Callable, Iterator, Optional, Sequence, TypeVar
from .cache import Cache as Cache
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
class RRCache(Cache[_KT, _VT]):
def __init__(
self,
maxsize: int,
choice: Optional[Callable[[Sequence[_KT]], _KT]] = ...,
getsizeof: Optional[Callable[[_VT], int]] = ...,
) -> None: ...
def __getitem__(self, key: _KT) -> _VT: ...
def __setitem__(self, key: _KT, value: _VT) -> None: ...
def __delitem__(self, key: _KT) -> None: ...
def __iter__(self) -> Iterator[_KT]: ...
def __len__(self) -> int: ...
@property
def choice(self) -> Callable[[Sequence[_KT]], _KT]: ...

23
third_party/2and3/cachetools/ttl.pyi vendored Normal file
View File

@@ -0,0 +1,23 @@
from typing import Callable, Iterator, Optional, TypeVar
from .cache import Cache
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
class TTLCache(Cache[_KT, _VT]):
def __init__(
self, maxsize: int, ttl: int, timer: Callable[[], float] = ..., getsizeof: Optional[Callable[[_VT], int]] = ...
) -> None: ...
def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ...
def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ...
def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ...
def __iter__(self) -> Iterator[_KT]: ...
def __len__(self) -> int: ...
@property
def currsize(self) -> int: ...
@property
def timer(self) -> Callable[[], float]: ...
@property
def ttl(self) -> int: ...
def expire(self, time: Optional[Callable[[], float]] = ...) -> None: ...