1
- __all__ = ("HasArrayNamespace" ,)
1
+ __all__ = (
2
+ "Array" ,
3
+ "HasArrayNamespace" ,
4
+ )
2
5
3
6
from types import ModuleType
4
7
from typing import Literal , Protocol
@@ -12,7 +15,7 @@ class HasArrayNamespace(Protocol[NamespaceT_co]):
12
15
13
16
This `Protocol` is intended for use in static typing to ensure that an
14
17
object has an `__array_namespace__` method that returns a namespace for
15
- array operations. This `Protocol` should not be used at runtime, for type
18
+ array operations. This `Protocol` should not be used at runtime for type
16
19
checking or as a base class.
17
20
18
21
Example:
@@ -52,3 +55,26 @@ def __array_namespace__(
52
55
53
56
"""
54
57
...
58
+
59
+
60
+ class Array (
61
+ HasArrayNamespace [NamespaceT_co ],
62
+ # -------------------------
63
+ Protocol [NamespaceT_co ],
64
+ ):
65
+ """Array API specification for array object attributes and methods.
66
+
67
+ The type is: ``Array[+NamespaceT = ModuleType] = Array[NamespaceT]`` where:
68
+
69
+ - `NamespaceT` is the type of the array namespace. It defaults to
70
+ `ModuleType`, which is the most common form of array namespace (e.g.,
71
+ `numpy`, `cupy`, etc.). However, it can be any type, e.g. a
72
+ `types.SimpleNamespace`, to allow for wrapper libraries to
73
+ semi-dynamically define their own array namespaces based on the wrapped
74
+ array type.
75
+
76
+ This type is intended for use in static typing to ensure that an object has
77
+ the attributes and methods defined in the array API specification. It should
78
+ not be used at runtime for type checking or as a base class.
79
+
80
+ """
0 commit comments