From 30f3d12426115587ee13487e54376bc4f6d679c8 Mon Sep 17 00:00:00 2001 From: Sagi Buchbinder Shadur Date: Sun, 17 Aug 2025 00:39:46 -0400 Subject: [PATCH 1/3] Add datetime types for the TTLCache class --- stubs/cachetools/cachetools/__init__.pyi | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 4a8a52687ba4..cb7b53e18b7b 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -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 @@ -76,14 +77,22 @@ 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]): def __init__( From 4b0113842b7d0409baa6d53045bf98ce410ebc38 Mon Sep 17 00:00:00 2001 From: Sagi Buchbinder Shadur Date: Sun, 17 Aug 2025 00:41:29 -0400 Subject: [PATCH 2/3] Add datetime types for the TLRUCache class --- stubs/cachetools/cachetools/__init__.pyi | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index cb7b53e18b7b..9e2c1fa4b4c6 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -95,6 +95,7 @@ class TTLCache(_TimedCache[_KT, _VT]): def expire(self, time: float | datetime | None = None) -> list[tuple[_KT, _VT]]: ... class TLRUCache(_TimedCache[_KT, _VT]): + @overload def __init__( self, maxsize: float, @@ -102,9 +103,17 @@ class TLRUCache(_TimedCache[_KT, _VT]): 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( From 0ab45b5e9e51f7e35cb9f630711bef5f2a9af556 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 17 Aug 2025 04:48:45 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/cachetools/cachetools/__init__.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 9e2c1fa4b4c6..083e777045e2 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -81,7 +81,9 @@ class TTLCache(_TimedCache[_KT, _VT]): @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: ... + 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]