Re-organize directory structure (#4971)

See discussion in #2491

Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
This commit is contained in:
Ivan Levkivskyi
2021-01-27 12:00:39 +00:00
committed by GitHub
parent 869238e587
commit 16ae4c6120
1399 changed files with 601 additions and 97 deletions

View File

@@ -0,0 +1,2 @@
version = "0.1"
python2 = true

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

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): ...

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,16 @@
from typing import Any, Callable, ContextManager, MutableMapping, Optional, TypeVar
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
_T = TypeVar("_T", bound=Callable[..., Any])
_T_co = TypeVar("_T_co", covariant=True)
_T_self = TypeVar("_T_self")
def cached(
cache: Optional[MutableMapping[_KT, _VT]], key: Callable[..., _KT] = ..., lock: Optional[ContextManager[_T_co]] = ...
) -> Callable[[_T], _T]: ...
def cachedmethod(
cache: Callable[[_T_self], Optional[MutableMapping[_KT, _VT]]],
key: Callable[..., _KT] = ...,
lock: Optional[ContextManager[_T_co]] = ...,
) -> Callable[[_T], _T]: ...

View File

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

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: ...

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]: ...

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]: ...

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: float, 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) -> float: ...
def expire(self, time: Optional[Callable[[], float]] = ...) -> None: ...