Skip to content

Commit a7798f6

Browse files
authored
Revert "lru_cache preserves signature of wrapped function (#6221)" (#6356)
This reverts commit 8bda66a. The change causes issues with ParamSpec implementations in type checkers, at least pyright and my work-in-progress support for ParamSpec in mypy. It's not yet clear how to fix the issues, so I think that it's best to revert this, at least temporarily until we've found a good solution. See #6347 for context.
1 parent 25649bc commit a7798f6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

stdlib/functools.pyi

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
import types
33
from _typeshed import SupportsItems, SupportsLessThan
44
from typing import Any, Callable, Generic, Hashable, Iterable, NamedTuple, Sequence, Sized, Tuple, Type, TypeVar, overload
5-
from typing_extensions import ParamSpec, final
5+
from typing_extensions import final
66

77
if sys.version_info >= (3, 9):
88
from types import GenericAlias
@@ -11,7 +11,6 @@ _AnyCallable = Callable[..., Any]
1111

1212
_T = TypeVar("_T")
1313
_S = TypeVar("_S")
14-
_P = ParamSpec("_P")
1514

1615
@overload
1716
def reduce(function: Callable[[_T, _S], _T], sequence: Iterable[_S], initial: _T) -> _T: ...
@@ -25,20 +24,20 @@ class _CacheInfo(NamedTuple):
2524
currsize: int
2625

2726
@final
28-
class _lru_cache_wrapper(Generic[_P, _T]): # type: ignore
29-
__wrapped__: Callable[_P, _T] # type: ignore
30-
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _T: ... # type: ignore
27+
class _lru_cache_wrapper(Generic[_T]):
28+
__wrapped__: Callable[..., _T]
29+
def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T: ...
3130
def cache_info(self) -> _CacheInfo: ...
3231
def cache_clear(self) -> None: ...
3332

3433
if sys.version_info >= (3, 8):
3534
@overload
36-
def lru_cache(maxsize: int | None = ..., typed: bool = ...) -> Callable[[Callable[_P, _T]], _lru_cache_wrapper[_P, _T]]: ... # type: ignore
35+
def lru_cache(maxsize: int | None = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
3736
@overload
38-
def lru_cache(maxsize: Callable[_P, _T], typed: bool = ...) -> _lru_cache_wrapper[_P, _T]: ... # type: ignore
37+
def lru_cache(maxsize: Callable[..., _T], typed: bool = ...) -> _lru_cache_wrapper[_T]: ...
3938

4039
else:
41-
def lru_cache(maxsize: int | None = ..., typed: bool = ...) -> Callable[[Callable[_P, _T]], _lru_cache_wrapper[_P, _T]]: ... # type: ignore
40+
def lru_cache(maxsize: int | None = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
4241

4342
WRAPPER_ASSIGNMENTS: Sequence[str]
4443
WRAPPER_UPDATES: Sequence[str]
@@ -118,7 +117,7 @@ if sys.version_info >= (3, 8):
118117
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
119118

120119
if sys.version_info >= (3, 9):
121-
def cache(__user_function: Callable[_P, _T]) -> _lru_cache_wrapper[_P, _T]: ... # type: ignore
120+
def cache(__user_function: Callable[..., _T]) -> _lru_cache_wrapper[_T]: ...
122121

123122
def _make_key(
124123
args: Tuple[Hashable, ...],

0 commit comments

Comments
 (0)