Skip to content

Commit 29c85f3

Browse files
jorenhamseberg
andauthored
TYP: Accept dispatcher function with optional returns in _core.overrides (#29171)
Co-authored-by: Sebastian Berg <sebastianb@nvidia.com>
1 parent 44d3cf1 commit 29c85f3

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

numpy/_core/overrides.pyi

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
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
53

64
_T = TypeVar("_T")
75
_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]]
99

1010
###
1111

@@ -18,31 +18,28 @@ class ArgSpec(NamedTuple):
1818
keywords: str | None
1919
defaults: tuple[Any, ...]
2020

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: ...
2323

2424
#
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: ...
2926

3027
# NOTE: This actually returns a `_ArrayFunctionDispatcher` callable wrapper object, with
3128
# the original wrapped callable stored in the `._implementation` attribute. It checks
3229
# for any `__array_function__` of the values of specific arguments that the dispatcher
3330
# specifies. Since the dispatcher only returns an iterable of passed array-like args,
3431
# this overridable behaviour is impossible to annotate.
3532
def array_function_dispatch(
36-
dispatcher: Callable[_Tss, Iterable[_SupportsArrayFunc]] | None = None,
33+
dispatcher: _Dispatcher[_Tss] | None = None,
3734
module: str | None = None,
3835
verify: bool = True,
3936
docs_from_dispatcher: bool = False,
40-
) -> Callable[[_FuncT], _FuncT]: ...
37+
) -> Callable[[_FuncLikeT], _FuncLikeT]: ...
4138

4239
#
4340
def array_function_from_dispatcher(
4441
implementation: Callable[_Tss, _T],
4542
module: str | None = None,
4643
verify: bool = True,
4744
docs_from_dispatcher: bool = True,
48-
) -> Callable[[Callable[_Tss, Iterable[_SupportsArrayFunc]]], Callable[_Tss, _T]]: ...
45+
) -> Callable[[_Dispatcher[_Tss]], Callable[_Tss, _T]]: ...

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy