Skip to content

Commit 87af21d

Browse files
committed
[cachetools] Add @type_check_only to stub-only private classes
Also unify duplicated `_CacheInfo` definitions
1 parent eca2ee5 commit 87af21d

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

stubs/cachetools/cachetools/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from _typeshed import IdentityFunction, Unused
22
from collections.abc import Callable, Iterator, MutableMapping, Sequence
33
from contextlib import AbstractContextManager
44
from threading import Condition
5-
from typing import Any, Generic, Literal, NamedTuple, TypeVar, overload
5+
from typing import Any, Generic, Literal, NamedTuple, TypeVar, overload, type_check_only
66
from typing_extensions import Self, deprecated
77

88
__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod")
@@ -106,10 +106,12 @@ class _CacheInfo(NamedTuple):
106106
maxsize: int | None
107107
currsize: int
108108

109+
@type_check_only
109110
class _cached_wrapper(Generic[_R]):
110111
__wrapped__: Callable[..., _R]
111112
def __call__(self, /, *args: Any, **kwargs: Any) -> _R: ...
112113

114+
@type_check_only
113115
class _cached_wrapper_info(_cached_wrapper[_R]):
114116
def cache_info(self) -> _CacheInfo: ...
115117
def cache_clear(self) -> None: ...

stubs/cachetools/cachetools/func.pyi

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
from collections.abc import Callable, Sequence
2-
from typing import Any, Final, Generic, NamedTuple, TypeVar, overload
2+
from typing import Any, Final, Generic, TypeVar, overload, type_check_only
3+
4+
from . import _CacheInfo
35

46
__all__: Final = ("fifo_cache", "lfu_cache", "lru_cache", "rr_cache", "ttl_cache")
57

68
_T = TypeVar("_T")
79
_R = TypeVar("_R")
810

9-
class _CacheInfo(NamedTuple):
10-
hits: int
11-
misses: int
12-
maxsize: int | None
13-
currsize: int
14-
11+
@type_check_only
1512
class _cachetools_cache_wrapper(Generic[_R]):
1613
__wrapped__: Callable[..., _R]
1714
def __call__(self, /, *args: Any, **kwargs: Any) -> _R: ...

0 commit comments

Comments
 (0)