summaryrefslogtreecommitdiff
path: root/numpy/array_api/_typing.py
diff options
context:
space:
mode:
authorDeveloper-Ecosystem-Engineering <65677710+Developer-Ecosystem-Engineering@users.noreply.github.com>2021-11-18 14:32:20 -0800
committerDeveloper-Ecosystem-Engineering <65677710+Developer-Ecosystem-Engineering@users.noreply.github.com>2021-11-18 14:32:20 -0800
commit9fe353e048bc317099bb13cae4cb5a4de8c0c656 (patch)
tree4976e4328da9906d99cd2478547ca1e2829e071d /numpy/array_api/_typing.py
parent66ca468b97873c1c8bfe69bddac6df633780c71c (diff)
parent5e9ce0c0529e3085498ac892941a020a65c7369a (diff)
downloadnumpy-9fe353e048bc317099bb13cae4cb5a4de8c0c656.tar.gz
Merge branch 'as_min_max' of https://github.com/Developer-Ecosystem-Engineering/numpy into as_min_max
Diffstat (limited to 'numpy/array_api/_typing.py')
-rw-r--r--numpy/array_api/_typing.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/numpy/array_api/_typing.py b/numpy/array_api/_typing.py
index 519e8463c..dfa87b358 100644
--- a/numpy/array_api/_typing.py
+++ b/numpy/array_api/_typing.py
@@ -6,6 +6,8 @@ annotations in the function signatures. The functions in the module are only
valid for inputs that match the given type annotations.
"""
+from __future__ import annotations
+
__all__ = [
"Array",
"Device",
@@ -16,7 +18,16 @@ __all__ = [
]
import sys
-from typing import Any, Literal, Sequence, Type, Union, TYPE_CHECKING, TypeVar
+from typing import (
+ Any,
+ Literal,
+ Sequence,
+ Type,
+ Union,
+ TYPE_CHECKING,
+ TypeVar,
+ Protocol,
+)
from ._array_object import Array
from numpy import (
@@ -33,10 +44,11 @@ from numpy import (
float64,
)
-# This should really be recursive, but that isn't supported yet. See the
-# similar comment in numpy/typing/_array_like.py
-_T = TypeVar("_T")
-NestedSequence = Sequence[Sequence[_T]]
+_T_co = TypeVar("_T_co", covariant=True)
+
+class NestedSequence(Protocol[_T_co]):
+ def __getitem__(self, key: int, /) -> _T_co | NestedSequence[_T_co]: ...
+ def __len__(self, /) -> int: ...
Device = Literal["cpu"]
if TYPE_CHECKING or sys.version_info >= (3, 9):
@@ -55,6 +67,8 @@ if TYPE_CHECKING or sys.version_info >= (3, 9):
else:
Dtype = dtype
-SupportsDLPack = Any
SupportsBufferProtocol = Any
PyCapsule = Any
+
+class SupportsDLPack(Protocol):
+ def __dlpack__(self, /, *, stream: None = ...) -> PyCapsule: ...