summaryrefslogtreecommitdiff
path: root/numpy/array_api/_typing.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-09-30 16:56:30 -0700
committerGitHub <noreply@github.com>2021-09-30 16:56:30 -0700
commit561ddde76856a09560159013c5d7a97f62d48a25 (patch)
tree884aaf33fe12476a3e6ca1446ba7687e23b26820 /numpy/array_api/_typing.py
parentb40078630b0ec16280cd06b0cbbb3cef42901138 (diff)
parent9c356d55d78620532ed92987af1721d7ca4034ec (diff)
downloadnumpy-561ddde76856a09560159013c5d7a97f62d48a25.tar.gz
Merge pull request #19969 from BvB93/array-api
MAINT: Misc `np.array_api` annotation fixes
Diffstat (limited to 'numpy/array_api/_typing.py')
-rw-r--r--numpy/array_api/_typing.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/numpy/array_api/_typing.py b/numpy/array_api/_typing.py
index 5f937a56c..519e8463c 100644
--- a/numpy/array_api/_typing.py
+++ b/numpy/array_api/_typing.py
@@ -15,10 +15,12 @@ __all__ = [
"PyCapsule",
]
-from typing import Any, Literal, Sequence, Type, Union
+import sys
+from typing import Any, Literal, Sequence, Type, Union, TYPE_CHECKING, TypeVar
-from . import (
- Array,
+from ._array_object import Array
+from numpy import (
+ dtype,
int8,
int16,
int32,
@@ -33,12 +35,26 @@ from . import (
# This should really be recursive, but that isn't supported yet. See the
# similar comment in numpy/typing/_array_like.py
-NestedSequence = Sequence[Sequence[Any]]
+_T = TypeVar("_T")
+NestedSequence = Sequence[Sequence[_T]]
Device = Literal["cpu"]
-Dtype = Type[
- Union[int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64]
-]
+if TYPE_CHECKING or sys.version_info >= (3, 9):
+ Dtype = dtype[Union[
+ int8,
+ int16,
+ int32,
+ int64,
+ uint8,
+ uint16,
+ uint32,
+ uint64,
+ float32,
+ float64,
+ ]]
+else:
+ Dtype = dtype
+
SupportsDLPack = Any
SupportsBufferProtocol = Any
PyCapsule = Any