Skip to content

Commit 19afbae

Browse files
committed
static typing and documentation
Signed-off-by: nstarman <[email protected]>
1 parent d678336 commit 19afbae

File tree

9 files changed

+161
-122
lines changed

9 files changed

+161
-122
lines changed

.pre-commit-config.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,29 @@ repos:
4848
rev: 23.7.0
4949
hooks:
5050
- id: black
51+
52+
- repo: https://github.com/pre-commit/mirrors-mypy
53+
rev: "v1.0.0"
54+
hooks:
55+
- id: mypy
56+
additional_dependencies: [typing_extensions>=4.4.0]
57+
args:
58+
- --ignore-missing-imports
59+
- --config=pyproject.toml
60+
files: ".*(_draft.*)$"
61+
exclude: |
62+
(?x)^(
63+
.*creation_functions.py|
64+
.*data_type_functions.py|
65+
.*elementwise_functions.py|
66+
.*fft.py|
67+
.*indexing_functions.py|
68+
.*linalg.py|
69+
.*linear_algebra_functions.py|
70+
.*manipulation_functions.py|
71+
.*searching_functions.py|
72+
.*set_functions.py|
73+
.*sorting_functions.py|
74+
.*statistical_functions.py|
75+
.*utility_functions.py|
76+
)$

pyproject.toml

+10
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,15 @@ doc = [
3030
requires = ["setuptools"]
3131
build-backend = "setuptools.build_meta"
3232

33+
3334
[tool.black]
3435
line-length = 88
36+
37+
38+
[tool.mypy]
39+
python_version = "3.9"
40+
mypy_path = "$MYPY_CONFIG_FILE_DIR/src/array_api_stubs/_draft/"
41+
files = [
42+
"src/array_api_stubs/_draft/**/*.py"
43+
]
44+
follow_imports = "silent"

spec/draft/API_specification/array_object.rst

+63-63
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,47 @@ Arithmetic Operators
3030

3131
A conforming implementation of the array API standard must provide and support an array object supporting the following Python arithmetic operators.
3232

33-
- ``+x``: :meth:`.array.__pos__`
33+
- ``+x``: :meth:`.Array.__pos__`
3434

3535
- `operator.pos(x) <https://docs.python.org/3/library/operator.html#operator.pos>`_
3636
- `operator.__pos__(x) <https://docs.python.org/3/library/operator.html#operator.__pos__>`_
3737

38-
- `-x`: :meth:`.array.__neg__`
38+
- `-x`: :meth:`.Array.__neg__`
3939

4040
- `operator.neg(x) <https://docs.python.org/3/library/operator.html#operator.neg>`_
4141
- `operator.__neg__(x) <https://docs.python.org/3/library/operator.html#operator.__neg__>`_
4242

43-
- `x1 + x2`: :meth:`.array.__add__`
43+
- `x1 + x2`: :meth:`.Array.__add__`
4444

4545
- `operator.add(x1, x2) <https://docs.python.org/3/library/operator.html#operator.add>`_
4646
- `operator.__add__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__add__>`_
4747

48-
- `x1 - x2`: :meth:`.array.__sub__`
48+
- `x1 - x2`: :meth:`.Array.__sub__`
4949

5050
- `operator.sub(x1, x2) <https://docs.python.org/3/library/operator.html#operator.sub>`_
5151
- `operator.__sub__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__sub__>`_
5252

53-
- `x1 * x2`: :meth:`.array.__mul__`
53+
- `x1 * x2`: :meth:`.Array.__mul__`
5454

5555
- `operator.mul(x1, x2) <https://docs.python.org/3/library/operator.html#operator.mul>`_
5656
- `operator.__mul__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__mul__>`_
5757

58-
- `x1 / x2`: :meth:`.array.__truediv__`
58+
- `x1 / x2`: :meth:`.Array.__truediv__`
5959

6060
- `operator.truediv(x1,x2) <https://docs.python.org/3/library/operator.html#operator.truediv>`_
6161
- `operator.__truediv__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__truediv__>`_
6262

63-
- `x1 // x2`: :meth:`.array.__floordiv__`
63+
- `x1 // x2`: :meth:`.Array.__floordiv__`
6464

6565
- `operator.floordiv(x1, x2) <https://docs.python.org/3/library/operator.html#operator.floordiv>`_
6666
- `operator.__floordiv__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__floordiv__>`_
6767

68-
- `x1 % x2`: :meth:`.array.__mod__`
68+
- `x1 % x2`: :meth:`.Array.__mod__`
6969

7070
- `operator.mod(x1, x2) <https://docs.python.org/3/library/operator.html#operator.mod>`_
7171
- `operator.__mod__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__mod__>`_
7272

73-
- `x1 ** x2`: :meth:`.array.__pow__`
73+
- `x1 ** x2`: :meth:`.Array.__pow__`
7474

7575
- `operator.pow(x1, x2) <https://docs.python.org/3/library/operator.html#operator.pow>`_
7676
- `operator.__pow__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__pow__>`_
@@ -82,7 +82,7 @@ Array Operators
8282

8383
A conforming implementation of the array API standard must provide and support an array object supporting the following Python array operators.
8484

85-
- `x1 @ x2`: :meth:`.array.__matmul__`
85+
- `x1 @ x2`: :meth:`.Array.__matmul__`
8686

8787
- `operator.matmul(x1, x2) <https://docs.python.org/3/library/operator.html#operator.matmul>`_
8888
- `operator.__matmul__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__matmul__>`_
@@ -94,34 +94,34 @@ Bitwise Operators
9494

9595
A conforming implementation of the array API standard must provide and support an array object supporting the following Python bitwise operators.
9696

97-
- `~x`: :meth:`.array.__invert__`
97+
- `~x`: :meth:`.Array.__invert__`
9898

9999
- `operator.inv(x) <https://docs.python.org/3/library/operator.html#operator.inv>`_
100100
- `operator.invert(x) <https://docs.python.org/3/library/operator.html#operator.invert>`_
101101
- `operator.__inv__(x) <https://docs.python.org/3/library/operator.html#operator.__inv__>`_
102102
- `operator.__invert__(x) <https://docs.python.org/3/library/operator.html#operator.__invert__>`_
103103

104-
- `x1 & x2`: :meth:`.array.__and__`
104+
- `x1 & x2`: :meth:`.Array.__and__`
105105

106106
- `operator.and(x1, x2) <https://docs.python.org/3/library/operator.html#operator.and>`_
107107
- `operator.__and__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__and__>`_
108108

109-
- `x1 | x2`: :meth:`.array.__or__`
109+
- `x1 | x2`: :meth:`.Array.__or__`
110110

111111
- `operator.or(x1, x2) <https://docs.python.org/3/library/operator.html#operator.or>`_
112112
- `operator.__or__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__or__>`_
113113

114-
- `x1 ^ x2`: :meth:`.array.__xor__`
114+
- `x1 ^ x2`: :meth:`.Array.__xor__`
115115

116116
- `operator.xor(x1, x2) <https://docs.python.org/3/library/operator.html#operator.xor>`_
117117
- `operator.__xor__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__xor__>`_
118118

119-
- `x1 << x2`: :meth:`.array.__lshift__`
119+
- `x1 << x2`: :meth:`.Array.__lshift__`
120120

121121
- `operator.lshift(x1, x2) <https://docs.python.org/3/library/operator.html#operator.lshift>`_
122122
- `operator.__lshift__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__lshift__>`_
123123

124-
- `x1 >> x2`: :meth:`.array.__rshift__`
124+
- `x1 >> x2`: :meth:`.Array.__rshift__`
125125

126126
- `operator.rshift(x1, x2) <https://docs.python.org/3/library/operator.html#operator.rshift>`_
127127
- `operator.__rshift__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__rshift__>`_
@@ -133,32 +133,32 @@ Comparison Operators
133133

134134
A conforming implementation of the array API standard must provide and support an array object supporting the following Python comparison operators.
135135

136-
- `x1 < x2`: :meth:`.array.__lt__`
136+
- `x1 < x2`: :meth:`.Array.__lt__`
137137

138138
- `operator.lt(x1, x2) <https://docs.python.org/3/library/operator.html#operator.lt>`_
139139
- `operator.__lt__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__lt__>`_
140140

141-
- `x1 <= x2`: :meth:`.array.__le__`
141+
- `x1 <= x2`: :meth:`.Array.__le__`
142142

143143
- `operator.le(x1, x2) <https://docs.python.org/3/library/operator.html#operator.le>`_
144144
- `operator.__le__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__le__>`_
145145

146-
- `x1 > x2`: :meth:`.array.__gt__`
146+
- `x1 > x2`: :meth:`.Array.__gt__`
147147

148148
- `operator.gt(x1, x2) <https://docs.python.org/3/library/operator.html#operator.gt>`_
149149
- `operator.__gt__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__gt__>`_
150150

151-
- `x1 >= x2`: :meth:`.array.__ge__`
151+
- `x1 >= x2`: :meth:`.Array.__ge__`
152152

153153
- `operator.ge(x1, x2) <https://docs.python.org/3/library/operator.html#operator.ge>`_
154154
- `operator.__ge__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__ge__>`_
155155

156-
- `x1 == x2`: :meth:`.array.__eq__`
156+
- `x1 == x2`: :meth:`.Array.__eq__`
157157

158158
- `operator.eq(x1, x2) <https://docs.python.org/3/library/operator.html#operator.eq>`_
159159
- `operator.__eq__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__eq__>`_
160160

161-
- `x1 != x2`: :meth:`.array.__ne__`
161+
- `x1 != x2`: :meth:`.Array.__ne__`
162162

163163
- `operator.ne(x1, x2) <https://docs.python.org/3/library/operator.html#operator.ne>`_
164164
- `operator.__ne__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__ne__>`_
@@ -252,13 +252,13 @@ Attributes
252252
:toctree: generated
253253
:template: property.rst
254254

255-
array.dtype
256-
array.device
257-
array.mT
258-
array.ndim
259-
array.shape
260-
array.size
261-
array.T
255+
Array.dtype
256+
Array.device
257+
Array.mT
258+
Array.ndim
259+
Array.shape
260+
Array.size
261+
Array.T
262262

263263
-------------------------------------------------
264264

@@ -272,37 +272,37 @@ Methods
272272
:toctree: generated
273273
:template: property.rst
274274

275-
array.__abs__
276-
array.__add__
277-
array.__and__
278-
array.__array_namespace__
279-
array.__bool__
280-
array.__complex__
281-
array.__dlpack__
282-
array.__dlpack_device__
283-
array.__eq__
284-
array.__float__
285-
array.__floordiv__
286-
array.__ge__
287-
array.__getitem__
288-
array.__gt__
289-
array.__index__
290-
array.__int__
291-
array.__invert__
292-
array.__le__
293-
array.__lshift__
294-
array.__lt__
295-
array.__matmul__
296-
array.__mod__
297-
array.__mul__
298-
array.__ne__
299-
array.__neg__
300-
array.__or__
301-
array.__pos__
302-
array.__pow__
303-
array.__rshift__
304-
array.__setitem__
305-
array.__sub__
306-
array.__truediv__
307-
array.__xor__
308-
array.to_device
275+
Array.__abs__
276+
Array.__add__
277+
Array.__and__
278+
Array.__array_namespace__
279+
Array.__bool__
280+
Array.__complex__
281+
Array.__dlpack__
282+
Array.__dlpack_device__
283+
Array.__eq__
284+
Array.__float__
285+
Array.__floordiv__
286+
Array.__ge__
287+
Array.__getitem__
288+
Array.__gt__
289+
Array.__index__
290+
Array.__int__
291+
Array.__invert__
292+
Array.__le__
293+
Array.__lshift__
294+
Array.__lt__
295+
Array.__matmul__
296+
Array.__mod__
297+
Array.__mul__
298+
Array.__ne__
299+
Array.__neg__
300+
Array.__or__
301+
Array.__pos__
302+
Array.__pow__
303+
Array.__rshift__
304+
Array.__setitem__
305+
Array.__sub__
306+
Array.__truediv__
307+
Array.__xor__
308+
Array.to_device

spec/draft/purpose_and_scope.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ namespace (e.g. `import package_name.array_api`). This has two issues though:
317317

318318
To address both issues, a uniform way must be provided by a conforming
319319
implementation to access the API namespace, namely a [method on the array
320-
object](array.__array_namespace__):
320+
object](Array.__array_namespace__):
321321

322322
```
323323
xp = x.__array_namespace__()

src/_array_api_conf.py

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
nitpick_ignore_regex = [
6868
("py:class", ".*array"),
6969
("py:class", ".*device"),
70+
("py:class", ".*Device"),
7071
("py:class", ".*dtype"),
7172
("py:class", ".*Self"),
7273
("py:class", ".*NestedSequence"),
@@ -85,6 +86,7 @@
8586
"array": "array",
8687
"Device": "device",
8788
"Dtype": "dtype",
89+
"DType": "dtype",
8890
}
8991

9092
# Make autosummary show the signatures of functions in the tables using actual

src/array_api_stubs/_draft/_types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class finfo_object:
7272
max: float
7373
min: float
7474
smallest_normal: float
75-
dtype: dtype
75+
dtype: DType
7676

7777

7878
@dataclass
@@ -82,7 +82,7 @@ class iinfo_object:
8282
bits: int
8383
max: int
8484
min: int
85-
dtype: dtype
85+
dtype: DType
8686

8787

8888
_T_co = TypeVar("_T_co", covariant=True)

0 commit comments

Comments
 (0)