Skip to content

Commit

Permalink
Replace int with SupportsIndex in indexing methods hints
Browse files Browse the repository at this point in the history
  • Loading branch information
honno committed Mar 21, 2024
1 parent 630149c commit 753697f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/array_api_stubs/_draft/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

__all__ = ["array"]

from typing import SupportsIndex
from ._types import (
array,
dtype as Dtype,
Expand Down Expand Up @@ -604,11 +605,11 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
def __getitem__(
self: array,
key: Union[
int,
SupportsIndex,
slice,
ellipsis,
None,
Tuple[Union[int, slice, ellipsis, None], ...],
Tuple[Union[SupportsIndex, slice, ellipsis, None], ...],
array,
],
/,
Expand All @@ -620,9 +621,13 @@ def __getitem__(
----------
self: array
array instance.
key: Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, None], ...], array]
key: Union[SupportsIndex, slice, ellipsis, None, Tuple[Union[SupportsIndex, slice, ellipsis, None], ...], array]
index key.
.. note::
``key`` can only be an array if it is valid for boolean array indexing, or supports ``__index__()``.
Returns
-------
out: array
Expand Down Expand Up @@ -1077,7 +1082,7 @@ def __rshift__(self: array, other: Union[int, array], /) -> array:
def __setitem__(
self: array,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
SupportsIndex, slice, ellipsis, Tuple[Union[SupportsIndex, slice, ellipsis], ...], array
],
value: Union[int, float, bool, array],
/,
Expand All @@ -1089,11 +1094,13 @@ def __setitem__(
----------
self: array
array instance.
key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array]
key: Union[SupportsIndex, slice, ellipsis, Tuple[Union[SupportsIndex, slice, ellipsis], ...], array]
index key.
value: Union[int, float, bool, array]
value(s) to set. Must be compatible with ``self[key]`` (see :ref:`broadcasting`).
.. note::
``key`` can only be an array if it is valid for boolean array indexing, or supports ``__index__()``.
.. note::
Expand Down

0 comments on commit 753697f

Please sign in to comment.