1
1
import sys
2
2
import types
3
- from _typeshed import IdentityFunction , SupportsAllComparisons , SupportsItems
3
+ from _typeshed import SupportsAllComparisons , SupportsItems
4
4
from collections .abc import Callable , Hashable , Iterable , Sequence , Sized
5
5
from typing import Any , Generic , Literal , NamedTuple , TypedDict , TypeVar , final , overload
6
- from typing_extensions import Self , TypeAlias
6
+ from typing_extensions import ParamSpec , Self , TypeAlias
7
7
8
8
if sys .version_info >= (3 , 9 ):
9
9
from types import GenericAlias
@@ -27,11 +27,13 @@ __all__ = [
27
27
if sys .version_info >= (3 , 9 ):
28
28
__all__ += ["cache" ]
29
29
30
- _AnyCallable : TypeAlias = Callable [..., object ]
31
-
32
30
_T = TypeVar ("_T" )
33
31
_T_co = TypeVar ("_T_co" , covariant = True )
34
32
_S = TypeVar ("_S" )
33
+ _PWrapped = ParamSpec ("_PWrapped" )
34
+ _RWrapped = TypeVar ("_RWrapped" )
35
+ _PWrapper = ParamSpec ("_PWrapper" )
36
+ _RWrapper = TypeVar ("_RWrapper" )
35
37
36
38
@overload
37
39
def reduce (__function : Callable [[_T , _S ], _T ], __sequence : Iterable [_S ], __initial : _T ) -> _T : ...
@@ -81,31 +83,41 @@ else:
81
83
]
82
84
WRAPPER_UPDATES : tuple [Literal ["__dict__" ]]
83
85
86
+ class _Wrapped (Generic [_PWrapped , _RWrapped , _PWrapper , _RWrapper ]):
87
+ __wrapped__ : Callable [_PWrapped , _RWrapped ]
88
+ def __call__ (self , * args : _PWrapper .args , ** kwargs : _PWrapper .kwargs ) -> _RWrapper : ...
89
+ # as with ``Callable``, we'll assume that these attributes exist
90
+ __name__ : str
91
+ __qualname__ : str
92
+
93
+ class _Wrapper (Generic [_PWrapped , _RWrapped ]):
94
+ def __call__ (self , f : Callable [_PWrapper , _RWrapper ]) -> _Wrapped [_PWrapped , _RWrapped , _PWrapper , _RWrapper ]: ...
95
+
84
96
if sys .version_info >= (3 , 12 ):
85
97
def update_wrapper (
86
- wrapper : _T ,
87
- wrapped : _AnyCallable ,
98
+ wrapper : Callable [ _PWrapper , _RWrapper ] ,
99
+ wrapped : Callable [ _PWrapped , _RWrapped ] ,
88
100
assigned : Sequence [str ] = ("__module__" , "__name__" , "__qualname__" , "__doc__" , "__annotations__" , "__type_params__" ),
89
101
updated : Sequence [str ] = ("__dict__" ,),
90
- ) -> _T : ...
102
+ ) -> _Wrapped [ _PWrapped , _RWrapped , _PWrapper , _RWrapper ] : ...
91
103
def wraps (
92
- wrapped : _AnyCallable ,
104
+ wrapped : Callable [ _PWrapped , _RWrapped ] ,
93
105
assigned : Sequence [str ] = ("__module__" , "__name__" , "__qualname__" , "__doc__" , "__annotations__" , "__type_params__" ),
94
106
updated : Sequence [str ] = ("__dict__" ,),
95
- ) -> IdentityFunction : ...
107
+ ) -> _Wrapper [ _PWrapped , _RWrapped ] : ...
96
108
97
109
else :
98
110
def update_wrapper (
99
- wrapper : _T ,
100
- wrapped : _AnyCallable ,
111
+ wrapper : Callable [ _PWrapper , _RWrapper ] ,
112
+ wrapped : Callable [ _PWrapped , _RWrapped ] ,
101
113
assigned : Sequence [str ] = ("__module__" , "__name__" , "__qualname__" , "__doc__" , "__annotations__" ),
102
114
updated : Sequence [str ] = ("__dict__" ,),
103
- ) -> _T : ...
115
+ ) -> _Wrapped [ _PWrapped , _RWrapped , _PWrapper , _RWrapper ] : ...
104
116
def wraps (
105
- wrapped : _AnyCallable ,
117
+ wrapped : Callable [ _PWrapped , _RWrapped ] ,
106
118
assigned : Sequence [str ] = ("__module__" , "__name__" , "__qualname__" , "__doc__" , "__annotations__" ),
107
119
updated : Sequence [str ] = ("__dict__" ,),
108
- ) -> IdentityFunction : ...
120
+ ) -> _Wrapper [ _PWrapped , _RWrapped ] : ...
109
121
110
122
def total_ordering (cls : type [_T ]) -> type [_T ]: ...
111
123
def cmp_to_key (mycmp : Callable [[_T , _T ], int ]) -> Callable [[_T ], SupportsAllComparisons ]: ...
0 commit comments