1
1
from collections .abc import Callable , Iterable
2
- from typing import Any , Final , NamedTuple , ParamSpec , TypeVar
3
-
4
- from numpy ._typing import _SupportsArrayFunc
2
+ from typing import Any , Final , NamedTuple , ParamSpec , TypeAlias , TypeVar
5
3
6
4
_T = TypeVar ("_T" )
7
5
_Tss = ParamSpec ("_Tss" )
8
- _FuncT = TypeVar ("_FuncT" , bound = Callable [..., object ])
6
+ _FuncLikeT = TypeVar ("_FuncLikeT" , bound = type | Callable [..., object ])
7
+
8
+ _Dispatcher : TypeAlias = Callable [_Tss , Iterable [object ]]
9
9
10
10
###
11
11
@@ -18,31 +18,28 @@ class ArgSpec(NamedTuple):
18
18
keywords : str | None
19
19
defaults : tuple [Any , ...]
20
20
21
- def get_array_function_like_doc (public_api : Callable [..., Any ], docstring_template : str = "" ) -> str : ...
22
- def finalize_array_function_like (public_api : _FuncT ) -> _FuncT : ...
21
+ def get_array_function_like_doc (public_api : Callable [..., object ], docstring_template : str = "" ) -> str : ...
22
+ def finalize_array_function_like (public_api : _FuncLikeT ) -> _FuncLikeT : ...
23
23
24
24
#
25
- def verify_matching_signatures (
26
- implementation : Callable [_Tss , object ],
27
- dispatcher : Callable [_Tss , Iterable [_SupportsArrayFunc ]],
28
- ) -> None : ...
25
+ def verify_matching_signatures (implementation : Callable [_Tss , object ], dispatcher : _Dispatcher [_Tss ]) -> None : ...
29
26
30
27
# NOTE: This actually returns a `_ArrayFunctionDispatcher` callable wrapper object, with
31
28
# the original wrapped callable stored in the `._implementation` attribute. It checks
32
29
# for any `__array_function__` of the values of specific arguments that the dispatcher
33
30
# specifies. Since the dispatcher only returns an iterable of passed array-like args,
34
31
# this overridable behaviour is impossible to annotate.
35
32
def array_function_dispatch (
36
- dispatcher : Callable [_Tss , Iterable [ _SupportsArrayFunc ] ] | None = None ,
33
+ dispatcher : _Dispatcher [_Tss ] | None = None ,
37
34
module : str | None = None ,
38
35
verify : bool = True ,
39
36
docs_from_dispatcher : bool = False ,
40
- ) -> Callable [[_FuncT ], _FuncT ]: ...
37
+ ) -> Callable [[_FuncLikeT ], _FuncLikeT ]: ...
41
38
42
39
#
43
40
def array_function_from_dispatcher (
44
41
implementation : Callable [_Tss , _T ],
45
42
module : str | None = None ,
46
43
verify : bool = True ,
47
44
docs_from_dispatcher : bool = True ,
48
- ) -> Callable [[Callable [_Tss , Iterable [ _SupportsArrayFunc ] ]], Callable [_Tss , _T ]]: ...
45
+ ) -> Callable [[_Dispatcher [_Tss ]], Callable [_Tss , _T ]]: ...
0 commit comments