Skip to content

Commit 202f2b4

Browse files
committed
Add review changes
1 parent 337243a commit 202f2b4

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

spec/API_specification/signatures/_types.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
The type variables should be replaced with the actual types for a given
55
library, e.g., for NumPy TypeVar('array') would be replaced with ndarray.
66
"""
7+
from __future__ import annotations
78

89
from dataclasses import dataclass
9-
from typing import Any, List, Literal, Optional, Sequence, Tuple, TypeVar, Union
10+
from typing import Any, List, Literal, Optional, Sequence, Tuple, TypeVar, Union, Protocol
1011

1112
array = TypeVar('array')
1213
device = TypeVar('device')
@@ -32,9 +33,14 @@ class iinfo_object:
3233
max: int
3334
min: int
3435

35-
# This should really be recursive, but that isn't supported yet.
36-
NestedSequence = Sequence[Any]
36+
37+
_T_co = TypeVar("_T_co", covariant=True)
38+
39+
class NestedSequence(Protocol[_T_co]):
40+
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]: ...
41+
def __len__(self, /) -> int: ...
42+
3743

3844
__all__ = ['Any', 'List', 'Literal', 'NestedSequence', 'Optional',
3945
'PyCapsule', 'SupportsBufferProtocol', 'SupportsDLPack', 'Tuple', 'Union',
40-
'array', 'device', 'dtype', 'ellipsis', 'finfo_object', 'iinfo_object']
46+
'array', 'device', 'dtype', 'ellipsis', 'finfo_object', 'iinfo_object']

spec/API_specification/signatures/creation_functions.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ def asarray(obj: Union[array, bool, int, float, NestedSequence, SupportsBufferPr
4444
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from the data type(s) in ``obj``. If all input values are Python scalars, then
4545
4646
- if all values are of type ``bool``, the output data type must be ``bool``.
47-
- if the values are a mixture of ``bool``s and ``int``, the output data type must be the default integer data type.
48-
- if one or more values are ``float``s, the output data type must be the default floating-point data type.
47+
- if the values are a mixture of ``bool``\s and ``int``, the output data type must be the default integer data type.
48+
- if one or more values are ``float``\s, the output data type must be the default floating-point data type.
4949
5050
Default: ``None``.
51-
52-
**Note**
53-
54-
If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library.
55-
To perform an explicit cast, use :ref:`function-astype`.
5651
device: Optional[device]
5752
device on which to place the created array. If ``device`` is ``None`` and ``x`` is an array, the output array device must be inferred from ``x``. Default: ``None``.
5853
copy: Optional[bool]
@@ -62,6 +57,10 @@ def asarray(obj: Union[array, bool, int, float, NestedSequence, SupportsBufferPr
6257
-------
6358
out: array
6459
an array containing the data from ``obj``.
60+
61+
Notes
62+
-----
63+
- If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library. To perform an explicit cast, use :ref:`function-astype`.
6564
"""
6665

6766
def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
@@ -104,7 +103,7 @@ def empty_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[d
104103

105104
def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: int = 0, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
106105
"""
107-
Returns a two-dimensional array with ones on the ``k``th diagonal and zeros elsewhere.
106+
Returns a two-dimensional array with ones on the ``k``\th diagonal and zeros elsewhere.
108107
109108
Parameters
110109
----------
@@ -122,7 +121,7 @@ def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: int = 0, dtype: Opti
122121
Returns
123122
-------
124123
out: array
125-
an array where all elements are equal to zero, except for the ``k``th diagonal, whose values are equal to one.
124+
an array where all elements are equal to zero, except for the ``k``\th diagonal, whose values are equal to one.
126125
"""
127126

128127
def from_dlpack(x: object, /) -> array:
@@ -334,7 +333,7 @@ def triu(x: array, /, *, k: int = 0) -> array:
334333

335334
def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
336335
"""
337-
Returns a new array having a specified `shape` and filled with zeros.
336+
Returns a new array having a specified ``shape`` and filled with zeros.
338337
339338
Parameters
340339
----------

spec/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
autodoc_typehints = 'signature'
4747
add_module_names = False
4848
napoleon_custom_sections = [('Returns', 'params_style')]
49+
default_role = 'code'
4950

5051
# Add any paths that contain templates here, relative to this directory.
5152
templates_path = ['_templates']

0 commit comments

Comments
 (0)