Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d9f353

Browse files
authored
functools: Add cache_parameters method to _lru_cache_wrapper (#10076)
The docs says that `cache_parameters()` function was added in 3.9: https://docs.python.org/3/library/functools.html#functools.lru_cache Source: https://github.com/python/cpython/blob/af530469954e8ad49f1e071ef31c844b9bfda414/Lib/functools.py#L512 But, `typeshed` does not have it.
1 parent 2bfb6d8 commit 1d9f353

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

stdlib/functools.pyi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import types
33
from _typeshed import SupportsAllComparisons, SupportsItems
44
from collections.abc import Callable, Hashable, Iterable, Sequence, Sized
55
from typing import Any, Generic, NamedTuple, TypeVar, overload
6-
from typing_extensions import Literal, ParamSpec, Self, TypeAlias, final
6+
from typing_extensions import Literal, ParamSpec, Self, TypeAlias, TypedDict, final
77

88
if sys.version_info >= (3, 9):
99
from types import GenericAlias
@@ -46,12 +46,20 @@ class _CacheInfo(NamedTuple):
4646
maxsize: int | None
4747
currsize: int
4848

49+
if sys.version_info >= (3, 9):
50+
class _CacheParameters(TypedDict):
51+
maxsize: int
52+
typed: bool
53+
4954
@final
5055
class _lru_cache_wrapper(Generic[_T]):
5156
__wrapped__: Callable[..., _T]
5257
def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T: ...
5358
def cache_info(self) -> _CacheInfo: ...
5459
def cache_clear(self) -> None: ...
60+
if sys.version_info >= (3, 9):
61+
def cache_parameters(self) -> _CacheParameters: ...
62+
5563
def __copy__(self) -> _lru_cache_wrapper[_T]: ...
5664
def __deepcopy__(self, __memo: Any) -> _lru_cache_wrapper[_T]: ...
5765

tests/stubtest_allowlists/py310.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ contextlib.AbstractAsyncContextManager.__class_getitem__
1717
contextlib.AbstractContextManager.__class_getitem__
1818
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
1919
functools.cached_property.__set__ # Stub is a white lie; see comments in the stub
20+
functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically
2021
gettext.install
2122
gettext.translation
2223
hmac.new # Stub is a white lie; see comments in the stub

tests/stubtest_allowlists/py311.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum.auto.value
2121
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
2222
ftplib.FTP.trust_server_pasv_ipv4_address
2323
functools.cached_property.__set__ # Stub is a white lie; see comments in the stub
24+
functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically
2425
ipaddress.IPv4Interface.hostmask
2526
ipaddress.IPv6Interface.hostmask
2627
ipaddress._BaseNetwork.broadcast_address

tests/stubtest_allowlists/py39.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ contextlib.AbstractContextManager.__class_getitem__
3737
distutils.command.bdist_wininst # see #6523
3838
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
3939
functools.cached_property.__set__ # Stub is a white lie; see comments in the stub
40+
functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically
4041
gettext.install
4142
gettext.translation
4243
hmac.new # Stub is a white lie; see comments in the stub

0 commit comments

Comments
 (0)