Skip to content

Add datetime types to Cachetools' TTLCache and TLRUCache classes #14585

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
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
28 changes: 24 additions & 4 deletions stubs/cachetools/cachetools/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import IdentityFunction, Unused
from collections.abc import Callable, Iterator, MutableMapping, Sequence
from contextlib import AbstractContextManager
from datetime import datetime, timedelta
from threading import Condition
from typing import Any, TypeVar, overload
from typing_extensions import deprecated
Expand Down Expand Up @@ -76,26 +77,45 @@ class TTLCache(_TimedCache[_KT, _VT]):
@overload
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: None = None) -> None: ...
@overload
def __init__(self, maxsize: float, ttl: timedelta, timer: Callable[[], datetime] = ..., getsizeof: None = None) -> None: ...
@overload
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ...
@overload
def __init__(
self, maxsize: float, ttl: timedelta, timer: Callable[[], datetime], getsizeof: Callable[[_VT], float]
) -> None: ...
@overload
def __init__(
self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]
) -> None: ...
@overload
def __init__(
self, maxsize: float, ttl: timedelta, timer: Callable[[], datetime] = ..., *, getsizeof: Callable[[_VT], float]
) -> None: ...
@property
def ttl(self) -> float: ...
def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ...
def ttl(self) -> float | timedelta: ...
def expire(self, time: float | datetime | None = None) -> list[tuple[_KT, _VT]]: ...

class TLRUCache(_TimedCache[_KT, _VT]):
@overload
def __init__(
self,
maxsize: float,
ttu: Callable[[_KT, _VT, float], float],
timer: Callable[[], float] = ...,
getsizeof: Callable[[_VT], float] | None = None,
) -> None: ...
@overload
def __init__(
self,
maxsize: float,
ttu: Callable[[_KT, _VT, datetime], timedelta],
timer: Callable[[], datetime] = ...,
getsizeof: Callable[[_VT], float] | None = None,
) -> None: ...
@property
def ttu(self) -> Callable[[_KT, _VT, float], float]: ...
def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ...
def ttu(self) -> Callable[[_KT, _VT, float], float] | Callable[[_KT, _VT, datetime], timedelta]: ...
def expire(self, time: float | datetime | None = None) -> list[tuple[_KT, _VT]]: ...

@overload
def cached(
Expand Down
Loading