Skip to content

Commit f257a5c

Browse files
committed
Use positional-only syntax in the function stubs
Even though we can't actually test it, this makes it so that the stubs are more accurate for anyone who may want to copy the stubs for their implementation.
1 parent 48658e4 commit f257a5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+325
-393
lines changed

array_api_tests/function_stubs/array_object.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,169 +6,163 @@
66
77
See
88
https://github.com/data-apis/array-api/blob/master/spec/API_specification/array_object.md
9-
10-
Note, all non-keyword-only arguments are positional-only. We don't include that
11-
here because
12-
13-
1. The /, syntax for positional-only arguments is Python 3.8+ only, and
14-
2. There is no real way to test that anyway.
159
"""
1610

1711
from __future__ import annotations
1812

1913
from ._types import array
2014

21-
def __abs__(x: array) -> array:
15+
def __abs__(x: array, /) -> array:
2216
"""
2317
Note: __abs__ is a method of the array object.
2418
"""
2519
pass
2620

27-
def __add__(x1: array, x2: array) -> array:
21+
def __add__(x1: array, x2: array, /) -> array:
2822
"""
2923
Note: __add__ is a method of the array object.
3024
"""
3125
pass
3226

33-
def __and__(x1: array, x2: array) -> array:
27+
def __and__(x1: array, x2: array, /) -> array:
3428
"""
3529
Note: __and__ is a method of the array object.
3630
"""
3731
pass
3832

39-
def __eq__(x1: array, x2: array) -> array:
33+
def __eq__(x1: array, x2: array, /) -> array:
4034
"""
4135
Note: __eq__ is a method of the array object.
4236
"""
4337
pass
4438

45-
def __floordiv__(x1: array, x2: array) -> array:
39+
def __floordiv__(x1: array, x2: array, /) -> array:
4640
"""
4741
Note: __floordiv__ is a method of the array object.
4842
"""
4943
pass
5044

51-
def __ge__(x1: array, x2: array) -> array:
45+
def __ge__(x1: array, x2: array, /) -> array:
5246
"""
5347
Note: __ge__ is a method of the array object.
5448
"""
5549
pass
5650

57-
def __getitem__(x, key):
51+
def __getitem__(x, key, /):
5852
"""
5953
Note: __getitem__ is a method of the array object.
6054
"""
6155
pass
6256

63-
def __gt__(x1: array, x2: array) -> array:
57+
def __gt__(x1: array, x2: array, /) -> array:
6458
"""
6559
Note: __gt__ is a method of the array object.
6660
"""
6761
pass
6862

69-
def __invert__(x: array) -> array:
63+
def __invert__(x: array, /) -> array:
7064
"""
7165
Note: __invert__ is a method of the array object.
7266
"""
7367
pass
7468

75-
def __le__(x1: array, x2: array) -> array:
69+
def __le__(x1: array, x2: array, /) -> array:
7670
"""
7771
Note: __le__ is a method of the array object.
7872
"""
7973
pass
8074

81-
def __len__(x):
75+
def __len__(x, /):
8276
"""
8377
Note: __len__ is a method of the array object.
8478
"""
8579
pass
8680

87-
def __lshift__(x1: array, x2: array) -> array:
81+
def __lshift__(x1: array, x2: array, /) -> array:
8882
"""
8983
Note: __lshift__ is a method of the array object.
9084
"""
9185
pass
9286

93-
def __lt__(x1: array, x2: array) -> array:
87+
def __lt__(x1: array, x2: array, /) -> array:
9488
"""
9589
Note: __lt__ is a method of the array object.
9690
"""
9791
pass
9892

99-
def __matmul__(x1: array, x2: array) -> array:
93+
def __matmul__(x1: array, x2: array, /) -> array:
10094
"""
10195
Note: __matmul__ is a method of the array object.
10296
"""
10397
pass
10498

105-
def __mod__(x1: array, x2: array) -> array:
99+
def __mod__(x1: array, x2: array, /) -> array:
106100
"""
107101
Note: __mod__ is a method of the array object.
108102
"""
109103
pass
110104

111-
def __mul__(x1: array, x2: array) -> array:
105+
def __mul__(x1: array, x2: array, /) -> array:
112106
"""
113107
Note: __mul__ is a method of the array object.
114108
"""
115109
pass
116110

117-
def __ne__(x1: array, x2: array) -> array:
111+
def __ne__(x1: array, x2: array, /) -> array:
118112
"""
119113
Note: __ne__ is a method of the array object.
120114
"""
121115
pass
122116

123-
def __neg__(x: array) -> array:
117+
def __neg__(x: array, /) -> array:
124118
"""
125119
Note: __neg__ is a method of the array object.
126120
"""
127121
pass
128122

129-
def __or__(x1: array, x2: array) -> array:
123+
def __or__(x1: array, x2: array, /) -> array:
130124
"""
131125
Note: __or__ is a method of the array object.
132126
"""
133127
pass
134128

135-
def __pos__(x: array) -> array:
129+
def __pos__(x: array, /) -> array:
136130
"""
137131
Note: __pos__ is a method of the array object.
138132
"""
139133
pass
140134

141-
def __pow__(x1: array, x2: array) -> array:
135+
def __pow__(x1: array, x2: array, /) -> array:
142136
"""
143137
Note: __pow__ is a method of the array object.
144138
"""
145139
pass
146140

147-
def __rshift__(x1: array, x2: array) -> array:
141+
def __rshift__(x1: array, x2: array, /) -> array:
148142
"""
149143
Note: __rshift__ is a method of the array object.
150144
"""
151145
pass
152146

153-
def __setitem__(x, key, value):
147+
def __setitem__(x, key, value, /):
154148
"""
155149
Note: __setitem__ is a method of the array object.
156150
"""
157151
pass
158152

159-
def __sub__(x1: array, x2: array) -> array:
153+
def __sub__(x1: array, x2: array, /) -> array:
160154
"""
161155
Note: __sub__ is a method of the array object.
162156
"""
163157
pass
164158

165-
def __truediv__(x1: array, x2: array) -> array:
159+
def __truediv__(x1: array, x2: array, /) -> array:
166160
"""
167161
Note: __truediv__ is a method of the array object.
168162
"""
169163
pass
170164

171-
def __xor__(x1: array, x2: array) -> array:
165+
def __xor__(x1: array, x2: array, /) -> array:
172166
"""
173167
Note: __xor__ is a method of the array object.
174168
"""

array_api_tests/function_stubs/constants.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
77
See
88
https://github.com/data-apis/array-api/blob/master/spec/API_specification/constants.md
9-
10-
Note, all non-keyword-only arguments are positional-only. We don't include that
11-
here because
12-
13-
1. The /, syntax for positional-only arguments is Python 3.8+ only, and
14-
2. There is no real way to test that anyway.
159
"""
1610

1711
from __future__ import annotations

array_api_tests/function_stubs/creation_functions.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,43 @@
66
77
See
88
https://github.com/data-apis/array-api/blob/master/spec/API_specification/creation_functions.md
9-
10-
Note, all non-keyword-only arguments are positional-only. We don't include that
11-
here because
12-
13-
1. The /, syntax for positional-only arguments is Python 3.8+ only, and
14-
2. There is no real way to test that anyway.
159
"""
1610

1711
from __future__ import annotations
1812

1913
from ._types import Optional, Tuple, Union, array, device, dtype
2014

21-
def arange(start: Union[int, float], *, stop: Optional[Union[int, float]] = None, step: Union[int, float] = 1, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
15+
def arange(start: Union[int, float], /, *, stop: Optional[Union[int, float]] = None, step: Union[int, float] = 1, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
2216
pass
2317

24-
def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
18+
def empty(shape: Union[int, Tuple[int, ...]], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
2519
pass
2620

27-
def empty_like(x: array, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
21+
def empty_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
2822
pass
2923

30-
def eye(N: int, *, M: Optional[int] = None, k: Optional[int] = 0, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
24+
def eye(N: int, /, *, M: Optional[int] = None, k: Optional[int] = 0, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
3125
pass
3226

33-
def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
27+
def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
3428
pass
3529

36-
def full_like(x: array, fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
30+
def full_like(x: array, fill_value: Union[int, float], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
3731
pass
3832

39-
def linspace(start: Union[int, float], stop: Union[int, float], num: int, *, dtype: Optional[dtype] = None, device: Optional[device] = None, endpoint: Optional[bool] = True) -> array:
33+
def linspace(start: Union[int, float], stop: Union[int, float], num: int, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None, endpoint: Optional[bool] = True) -> array:
4034
pass
4135

42-
def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
36+
def ones(shape: Union[int, Tuple[int, ...]], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
4337
pass
4438

45-
def ones_like(x: array, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
39+
def ones_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
4640
pass
4741

48-
def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
42+
def zeros(shape: Union[int, Tuple[int, ...]], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
4943
pass
5044

51-
def zeros_like(x: array, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
45+
def zeros_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
5246
pass
5347

5448
__all__ = ['arange', 'empty', 'empty_like', 'eye', 'full', 'full_like', 'linspace', 'ones', 'ones_like', 'zeros', 'zeros_like']

0 commit comments

Comments
 (0)