Skip to content

Commit 0dd4b6f

Browse files
AlexWaygoodJelleZijlstra
authored andcommitted
Revert use of ParamSpec for functools.wraps
1 parent dd12a2d commit 0dd4b6f

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

mypy/typeshed/stdlib/functools.pyi

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import sys
22
import types
3-
from _typeshed import SupportsAllComparisons, SupportsItems
3+
from _typeshed import IdentityFunction, SupportsAllComparisons, SupportsItems
44
from collections.abc import Callable, Hashable, Iterable, Sequence, Sized
55
from typing import Any, Generic, Literal, NamedTuple, TypedDict, TypeVar, final, overload
6-
from typing_extensions import ParamSpec, Self, TypeAlias
6+
from typing_extensions import Self, TypeAlias
77

88
if sys.version_info >= (3, 9):
99
from types import GenericAlias
@@ -27,12 +27,10 @@ __all__ = [
2727
if sys.version_info >= (3, 9):
2828
__all__ += ["cache"]
2929

30+
_AnyCallable: TypeAlias = Callable[..., object]
31+
3032
_T = TypeVar("_T")
3133
_S = TypeVar("_S")
32-
_PWrapped = ParamSpec("_PWrapped")
33-
_RWrapped = TypeVar("_RWrapped")
34-
_PWrapper = ParamSpec("_PWrapper")
35-
_RWrapper = TypeVar("_RWrapper")
3634

3735
@overload
3836
def reduce(__function: Callable[[_T, _S], _T], __sequence: Iterable[_S], __initial: _T) -> _T: ...
@@ -82,41 +80,31 @@ else:
8280
]
8381
WRAPPER_UPDATES: tuple[Literal["__dict__"]]
8482

85-
class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]):
86-
__wrapped__: Callable[_PWrapped, _RWrapped]
87-
def __call__(self, *args: _PWrapper.args, **kwargs: _PWrapper.kwargs) -> _RWrapper: ...
88-
# as with ``Callable``, we'll assume that these attributes exist
89-
__name__: str
90-
__qualname__: str
91-
92-
class _Wrapper(Generic[_PWrapped, _RWrapped]):
93-
def __call__(self, f: Callable[_PWrapper, _RWrapper]) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ...
94-
9583
if sys.version_info >= (3, 12):
9684
def update_wrapper(
97-
wrapper: Callable[_PWrapper, _RWrapper],
98-
wrapped: Callable[_PWrapped, _RWrapped],
85+
wrapper: _T,
86+
wrapped: _AnyCallable,
9987
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"),
10088
updated: Sequence[str] = ("__dict__",),
101-
) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ...
89+
) -> _T: ...
10290
def wraps(
103-
wrapped: Callable[_PWrapped, _RWrapped],
91+
wrapped: _AnyCallable,
10492
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"),
10593
updated: Sequence[str] = ("__dict__",),
106-
) -> _Wrapper[_PWrapped, _RWrapped]: ...
94+
) -> IdentityFunction: ...
10795

10896
else:
10997
def update_wrapper(
110-
wrapper: Callable[_PWrapper, _RWrapper],
111-
wrapped: Callable[_PWrapped, _RWrapped],
98+
wrapper: _T,
99+
wrapped: _AnyCallable,
112100
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"),
113101
updated: Sequence[str] = ("__dict__",),
114-
) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ...
102+
) -> _T: ...
115103
def wraps(
116-
wrapped: Callable[_PWrapped, _RWrapped],
104+
wrapped: _AnyCallable,
117105
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"),
118106
updated: Sequence[str] = ("__dict__",),
119-
) -> _Wrapper[_PWrapped, _RWrapped]: ...
107+
) -> IdentityFunction: ...
120108

121109
def total_ordering(cls: type[_T]) -> type[_T]: ...
122110
def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], SupportsAllComparisons]: ...

0 commit comments

Comments
 (0)