Skip to content

Commit 344298e

Browse files
AlexWaygoodJelleZijlstra
authored andcommitted
Revert use of ParamSpec for functools.wraps
1 parent 3e5d813 commit 344298e

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, NamedTuple, TypeVar, overload
6-
from typing_extensions import Literal, ParamSpec, Self, TypeAlias, TypedDict, final
6+
from typing_extensions import Literal, Self, TypeAlias, TypedDict, final
77

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

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

3836
@overload
3937
def reduce(__function: Callable[[_T, _S], _T], __sequence: Iterable[_S], __initial: _T) -> _T: ...
@@ -87,41 +85,31 @@ else:
8785
]
8886
WRAPPER_UPDATES: tuple[Literal["__dict__"]]
8987

90-
class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]):
91-
__wrapped__: Callable[_PWrapped, _RWrapped]
92-
def __call__(self, *args: _PWrapper.args, **kwargs: _PWrapper.kwargs) -> _RWrapper: ...
93-
# as with ``Callable``, we'll assume that these attributes exist
94-
__name__: str
95-
__qualname__: str
96-
97-
class _Wrapper(Generic[_PWrapped, _RWrapped]):
98-
def __call__(self, f: Callable[_PWrapper, _RWrapper]) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ...
99-
10088
if sys.version_info >= (3, 12):
10189
def update_wrapper(
102-
wrapper: Callable[_PWrapper, _RWrapper],
103-
wrapped: Callable[_PWrapped, _RWrapped],
90+
wrapper: _T,
91+
wrapped: _AnyCallable,
10492
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"),
10593
updated: Sequence[str] = ("__dict__",),
106-
) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ...
94+
) -> _T: ...
10795
def wraps(
108-
wrapped: Callable[_PWrapped, _RWrapped],
96+
wrapped: _AnyCallable,
10997
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__", "__type_params__"),
11098
updated: Sequence[str] = ("__dict__",),
111-
) -> _Wrapper[_PWrapped, _RWrapped]: ...
99+
) -> IdentityFunction: ...
112100

113101
else:
114102
def update_wrapper(
115-
wrapper: Callable[_PWrapper, _RWrapper],
116-
wrapped: Callable[_PWrapped, _RWrapped],
103+
wrapper: _T,
104+
wrapped: _AnyCallable,
117105
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"),
118106
updated: Sequence[str] = ("__dict__",),
119-
) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ...
107+
) -> _T: ...
120108
def wraps(
121-
wrapped: Callable[_PWrapped, _RWrapped],
109+
wrapped: _AnyCallable,
122110
assigned: Sequence[str] = ("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"),
123111
updated: Sequence[str] = ("__dict__",),
124-
) -> _Wrapper[_PWrapped, _RWrapped]: ...
112+
) -> IdentityFunction: ...
125113

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

0 commit comments

Comments
 (0)