[cachetools] Add @type_check_only to stub-only private classes (#15516)

Also unify duplicated `_CacheInfo` definitions
This commit is contained in:
Brian Schubert
2026-03-16 03:50:07 -04:00
committed by GitHub
parent 2e0a8127f5
commit e71841fe4b
2 changed files with 7 additions and 8 deletions
+3 -1
View File
@@ -2,7 +2,7 @@ from _typeshed import IdentityFunction, Unused
from collections.abc import Callable, Iterator, MutableMapping, Sequence
from contextlib import AbstractContextManager
from threading import Condition
from typing import Any, Generic, Literal, NamedTuple, TypeVar, overload
from typing import Any, Generic, Literal, NamedTuple, TypeVar, overload, type_check_only
from typing_extensions import Self, deprecated
__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod")
@@ -106,10 +106,12 @@ class _CacheInfo(NamedTuple):
maxsize: int | None
currsize: int
@type_check_only
class _cached_wrapper(Generic[_R]):
__wrapped__: Callable[..., _R]
def __call__(self, /, *args: Any, **kwargs: Any) -> _R: ...
@type_check_only
class _cached_wrapper_info(_cached_wrapper[_R]):
def cache_info(self) -> _CacheInfo: ...
def cache_clear(self) -> None: ...
+4 -7
View File
@@ -1,17 +1,14 @@
from collections.abc import Callable, Sequence
from typing import Any, Final, Generic, NamedTuple, TypeVar, overload
from typing import Any, Final, Generic, TypeVar, overload, type_check_only
from . import _CacheInfo
__all__: Final = ("fifo_cache", "lfu_cache", "lru_cache", "rr_cache", "ttl_cache")
_T = TypeVar("_T")
_R = TypeVar("_R")
class _CacheInfo(NamedTuple):
hits: int
misses: int
maxsize: int | None
currsize: int
@type_check_only
class _cachetools_cache_wrapper(Generic[_R]):
__wrapped__: Callable[..., _R]
def __call__(self, /, *args: Any, **kwargs: Any) -> _R: ...