Skip to content

Commit fc1ff6f

Browse files
committed
Capitalize the names of the type hint types in the array API
That way they aren't ambiguous with the attributes with the same names.
1 parent 1379623 commit fc1ff6f

12 files changed

+178
-178
lines changed

numpy/_array_api/_array_object.py

Lines changed: 59 additions & 59 deletions
Large diffs are not rendered by default.

numpy/_array_api/_creation_functions.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from typing import TYPE_CHECKING
55
if TYPE_CHECKING:
66
from ._types import (List, Optional, SupportsDLPack,
7-
SupportsBufferProtocol, Tuple, Union, array, device,
8-
dtype)
7+
SupportsBufferProtocol, Tuple, Union, Array, Device,
8+
Dtype)
99
from collections.abc import Sequence
1010
from ._dtypes import _all_dtypes
1111

1212
import numpy as np
1313

14-
def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, SupportsBufferProtocol], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None, copy: Optional[bool] = None) -> array:
14+
def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, SupportsBufferProtocol], /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None, copy: Optional[bool] = None) -> Array:
1515
"""
1616
Array API compatible wrapper for :py:func:`np.asarray <numpy.asarray>`.
1717
@@ -37,7 +37,7 @@ def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, Su
3737
raise TypeError(f"The array_api namespace does not support the dtype '{res.dtype}'")
3838
return ndarray._new(res)
3939

40-
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:
40+
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:
4141
"""
4242
Array API compatible wrapper for :py:func:`np.arange <numpy.arange>`.
4343
@@ -49,7 +49,7 @@ def arange(start: Union[int, float], /, stop: Optional[Union[int, float]] = None
4949
raise NotImplementedError("Device support is not yet implemented")
5050
return ndarray._new(np.arange(start, stop=stop, step=step, dtype=dtype))
5151

52-
def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
52+
def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
5353
"""
5454
Array API compatible wrapper for :py:func:`np.empty <numpy.empty>`.
5555
@@ -61,7 +61,7 @@ def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None,
6161
raise NotImplementedError("Device support is not yet implemented")
6262
return ndarray._new(np.empty(shape, dtype=dtype))
6363

64-
def empty_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
64+
def empty_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
6565
"""
6666
Array API compatible wrapper for :py:func:`np.empty_like <numpy.empty_like>`.
6767
@@ -73,7 +73,7 @@ def empty_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[d
7373
raise NotImplementedError("Device support is not yet implemented")
7474
return ndarray._new(np.empty_like(x._array, dtype=dtype))
7575

76-
def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: Optional[int] = 0, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
76+
def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: Optional[int] = 0, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
7777
"""
7878
Array API compatible wrapper for :py:func:`np.eye <numpy.eye>`.
7979
@@ -85,11 +85,11 @@ def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: Optional[int] = 0, d
8585
raise NotImplementedError("Device support is not yet implemented")
8686
return ndarray._new(np.eye(n_rows, M=n_cols, k=k, dtype=dtype))
8787

88-
def from_dlpack(x: object, /) -> array:
88+
def from_dlpack(x: object, /) -> Array:
8989
# Note: dlpack support is not yet implemented on ndarray
9090
raise NotImplementedError("DLPack support is not yet implemented")
9191

92-
def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
92+
def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
9393
"""
9494
Array API compatible wrapper for :py:func:`np.full <numpy.full>`.
9595
@@ -108,7 +108,7 @@ def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, d
108108
raise TypeError("Invalid input to full")
109109
return ndarray._new(res)
110110

111-
def full_like(x: array, /, fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
111+
def full_like(x: Array, /, fill_value: Union[int, float], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
112112
"""
113113
Array API compatible wrapper for :py:func:`np.full_like <numpy.full_like>`.
114114
@@ -125,7 +125,7 @@ def full_like(x: array, /, fill_value: Union[int, float], *, dtype: Optional[dty
125125
raise TypeError("Invalid input to full_like")
126126
return ndarray._new(res)
127127

128-
def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *, dtype: Optional[dtype] = None, device: Optional[device] = None, endpoint: bool = True) -> array:
128+
def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None, endpoint: bool = True) -> Array:
129129
"""
130130
Array API compatible wrapper for :py:func:`np.linspace <numpy.linspace>`.
131131
@@ -137,7 +137,7 @@ def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *,
137137
raise NotImplementedError("Device support is not yet implemented")
138138
return ndarray._new(np.linspace(start, stop, num, dtype=dtype, endpoint=endpoint))
139139

140-
def meshgrid(*arrays: Sequence[array], indexing: str = 'xy') -> List[array, ...]:
140+
def meshgrid(*arrays: Sequence[Array], indexing: str = 'xy') -> List[Array, ...]:
141141
"""
142142
Array API compatible wrapper for :py:func:`np.meshgrid <numpy.meshgrid>`.
143143
@@ -146,7 +146,7 @@ def meshgrid(*arrays: Sequence[array], indexing: str = 'xy') -> List[array, ...]
146146
from ._array_object import ndarray
147147
return [ndarray._new(array) for array in np.meshgrid(*[a._array for a in arrays], indexing=indexing)]
148148

149-
def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
149+
def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
150150
"""
151151
Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`.
152152
@@ -158,7 +158,7 @@ def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, d
158158
raise NotImplementedError("Device support is not yet implemented")
159159
return ndarray._new(np.ones(shape, dtype=dtype))
160160

161-
def ones_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
161+
def ones_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
162162
"""
163163
Array API compatible wrapper for :py:func:`np.ones_like <numpy.ones_like>`.
164164
@@ -170,7 +170,7 @@ def ones_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[de
170170
raise NotImplementedError("Device support is not yet implemented")
171171
return ndarray._new(np.ones_like(x._array, dtype=dtype))
172172

173-
def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
173+
def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
174174
"""
175175
Array API compatible wrapper for :py:func:`np.zeros <numpy.zeros>`.
176176
@@ -182,7 +182,7 @@ def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None,
182182
raise NotImplementedError("Device support is not yet implemented")
183183
return ndarray._new(np.zeros(shape, dtype=dtype))
184184

185-
def zeros_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
185+
def zeros_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
186186
"""
187187
Array API compatible wrapper for :py:func:`np.zeros_like <numpy.zeros_like>`.
188188

numpy/_array_api/_data_type_functions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
from typing import TYPE_CHECKING
66
if TYPE_CHECKING:
7-
from ._types import List, Tuple, Union, array, dtype
7+
from ._types import List, Tuple, Union, Array, Dtype
88
from collections.abc import Sequence
99

1010
import numpy as np
1111

12-
def broadcast_arrays(*arrays: Sequence[array]) -> List[array]:
12+
def broadcast_arrays(*arrays: Sequence[Array]) -> List[Array]:
1313
"""
1414
Array API compatible wrapper for :py:func:`np.broadcast_arrays <numpy.broadcast_arrays>`.
1515
@@ -18,7 +18,7 @@ def broadcast_arrays(*arrays: Sequence[array]) -> List[array]:
1818
from ._array_object import ndarray
1919
return [ndarray._new(array) for array in np.broadcast_arrays(*[a._array for a in arrays])]
2020

21-
def broadcast_to(x: array, /, shape: Tuple[int, ...]) -> array:
21+
def broadcast_to(x: Array, /, shape: Tuple[int, ...]) -> Array:
2222
"""
2323
Array API compatible wrapper for :py:func:`np.broadcast_to <numpy.broadcast_to>`.
2424
@@ -27,7 +27,7 @@ def broadcast_to(x: array, /, shape: Tuple[int, ...]) -> array:
2727
from ._array_object import ndarray
2828
return ndarray._new(np.broadcast_to(x._array, shape))
2929

30-
def can_cast(from_: Union[dtype, array], to: dtype, /) -> bool:
30+
def can_cast(from_: Union[Dtype, Array], to: Dtype, /) -> bool:
3131
"""
3232
Array API compatible wrapper for :py:func:`np.can_cast <numpy.can_cast>`.
3333
@@ -38,23 +38,23 @@ def can_cast(from_: Union[dtype, array], to: dtype, /) -> bool:
3838
from_ = from_._array
3939
return np.can_cast(from_, to)
4040

41-
def finfo(type: Union[dtype, array], /) -> finfo_object:
41+
def finfo(type: Union[Dtype, Array], /) -> finfo_object:
4242
"""
4343
Array API compatible wrapper for :py:func:`np.finfo <numpy.finfo>`.
4444
4545
See its docstring for more information.
4646
"""
4747
return np.finfo(type)
4848

49-
def iinfo(type: Union[dtype, array], /) -> iinfo_object:
49+
def iinfo(type: Union[Dtype, Array], /) -> iinfo_object:
5050
"""
5151
Array API compatible wrapper for :py:func:`np.iinfo <numpy.iinfo>`.
5252
5353
See its docstring for more information.
5454
"""
5555
return np.iinfo(type)
5656

57-
def result_type(*arrays_and_dtypes: Sequence[Union[array, dtype]]) -> dtype:
57+
def result_type(*arrays_and_dtypes: Sequence[Union[Array, Dtype]]) -> Dtype:
5858
"""
5959
Array API compatible wrapper for :py:func:`np.result_type <numpy.result_type>`.
6060

0 commit comments

Comments
 (0)