8000 TYP: Add a protocol class representing `__array_function__` · rjeb/numpy@d2df8c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2df8c6

Browse files
committed
TYP: Add a protocol class representing __array_function__
1 parent 313b02d commit d2df8c6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

numpy/typing/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ class _8Bit(_16Bit): # type: ignore[misc]
343343
_ArrayLike,
344344
_FiniteNestedSequence,
345345
_SupportsArray,
346+
_SupportsArrayFunc,
346347
_ArrayLikeInt,
347348
_ArrayLikeBool_co,
348349
_ArrayLikeUInt_co,

numpy/typing/_array_like.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import annotations
22

3+
# NOTE: Import `Sequence` from `typing` as we it is needed for a type-alias,
4+
# not an annotation
5+
from collections.abc import Collection, Callable
36
from typing import Any, Sequence, Protocol, Union, TypeVar
47
from numpy import (
58
ndarray,
@@ -34,6 +37,17 @@ class _SupportsArray(Protocol[_DType_co]):
3437
def __array__(self) -> ndarray[Any, _DType_co]: ...
3538

3639

40+
class _SupportsArrayFunc(Protocol):
41+
"""A protocol class representing `~class.__array_function__`."""
42+
def __array_function__(
43+
self,
44+
func: Callable[..., Any],
45+
types: Collection[type[Any]],
46+
args: tuple[Any, ...],
47+
kwargs: dict[str, Any],
48+
) -> object: ...
49+
50+
3751
# TODO: Wait until mypy supports recursive objects in combination with typevars
3852
_FiniteNestedSequence = Union[
3953
_T,

0 commit comments

Comments
 (0)
0