Skip to content

Commit baa7059

Browse files
authored
MAINT: Bump ruff to v0.16 (#234)
Following up on #235 (ruff "safe" fixes) and #236 (ruff "unsafe" fixes), manually fix remaining issues flagged by ruff==0.16. Reviewed at #234
1 parent 6fcfd1b commit baa7059

7 files changed

Lines changed: 105 additions & 89 deletions

File tree

‎.github/workflows/ruff.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Install dependencies
1414
run: |
1515
python -m pip install --upgrade pip
16-
pip install "ruff<0.16"
16+
pip install "ruff"
1717
# Update output format to enable automatic inline annotations.
1818
- name: Run Ruff
1919
run: ruff check --output-format=github .

‎array_api_strict/_array_object.py‎

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,8 @@ def _validate_index(
394394
"zero-dimensional integer arrays and boolean arrays "
395395
"are specified in the Array API."
396396
)
397-
if op == "setitem":
398-
if isinstance(i, Array) and i.dtype in _integer_dtypes:
399-
raise IndexError("Fancy indexing __setitem__ is not supported.")
397+
if op == "setitem" and isinstance(i, Array) and i.dtype in _integer_dtypes:
398+
raise IndexError("Fancy indexing __setitem__ is not supported.")
400399

401400
nonexpanding_key = []
402401
single_axes = []
@@ -530,8 +529,8 @@ def __add__(self, other: Array | complex, /) -> Array:
530529
other = self._check_allowed_dtypes(other, "numeric", "__add__")
531530
if other is NotImplemented:
532531
return other
533-
self, other = self._normalize_two_args(self, other)
534-
res = self._array.__add__(other._array)
532+
_self, other = self._normalize_two_args(self, other)
533+
res = _self._array.__add__(other._array)
535534
return self.__class__._new(res, device=self.device)
536535

537536
def __and__(self, other: Array | int, /) -> Array:
@@ -542,8 +541,8 @@ def __and__(self, other: Array | int, /) -> Array:
542541
other = self._check_allowed_dtypes(other, "integer or boolean", "__and__")
543542
if other is NotImplemented:
544543
return other
545-
self, other = self._normalize_two_args(self, other)
546-
res = self._array.__and__(other._array)
544+
_self, other = self._normalize_two_args(self, other)
545+
res = _self._array.__and__(other._array)
547546
return self.__class__._new(res, device=self.device)
548547

549548
def __array_namespace__(self, /, *, api_version: str | None = None) -> ModuleType:
@@ -641,8 +640,8 @@ def __eq__(self, other: Array | complex, /) -> Array: # type: ignore[override]
641640
other = self._check_allowed_dtypes(other, "all", "__eq__")
642641
if other is NotImplemented:
643642
return other
644-
self, other = self._normalize_two_args(self, other)
645-
res = self._array.__eq__(other._array)
643+
_self, other = self._normalize_two_args(self, other)
644+
res = _self._array.__eq__(other._array)
646645
return self.__class__._new(res, device=self.device)
647646

648647
def __float__(self) -> float:
@@ -665,8 +664,8 @@ def __floordiv__(self, other: Array | float, /) -> Array:
665664
other = self._check_allowed_dtypes(other, "real numeric", "__floordiv__")
666665
if other is NotImplemented:
667666
return other
668-
self, other = self._normalize_two_args(self, other)
669-
res = self._array.__floordiv__(other._array)
667+
_self, other = self._normalize_two_args(self, other)
668+
res = _self._array.__floordiv__(other._array)
670669
return self.__class__._new(res, device=self.device)
671670

672671
def __ge__(self, other: Array | float, /) -> Array:
@@ -677,8 +676,8 @@ def __ge__(self, other: Array | float, /) -> Array:
677676
other = self._check_allowed_dtypes(other, "real numeric", "__ge__")
678677
if other is NotImplemented:
679678
return other
680-
self, other = self._normalize_two_args(self, other)
681-
res = self._array.__ge__(other._array)
679+
_self, other = self._normalize_two_args(self, other)
680+
res = _self._array.__ge__(other._array)
682681
return self.__class__._new(res, device=self.device)
683682

684683
def __getitem__(
@@ -729,8 +728,8 @@ def __gt__(self, other: Array | float, /) -> Array:
729728
other = self._check_allowed_dtypes(other, "real numeric", "__gt__")
730729
if other is NotImplemented:
731730
return other
732-
self, other = self._normalize_two_args(self, other)
733-
res = self._array.__gt__(other._array)
731+
_self, other = self._normalize_two_args(self, other)
732+
res = _self._array.__gt__(other._array)
734733
return self.__class__._new(res, device=other.device)
735734

736735
def __int__(self) -> int:
@@ -784,8 +783,8 @@ def __le__(self, other: Array | float, /) -> Array:
784783
other = self._check_allowed_dtypes(other, "real numeric", "__le__")
785784
if other is NotImplemented:
786785
return other
787-
self, other = self._normalize_two_args(self, other)
788-
res = self._array.__le__(other._array)
786+
_self, other = self._normalize_two_args(self, other)
787+
res = _self._array.__le__(other._array)
789788
return self.__class__._new(res, device=self.device)
790789

791790
def __lshift__(self, other: Array | int, /) -> Array:
@@ -796,8 +795,8 @@ def __lshift__(self, other: Array | int, /) -> Array:
796795
other = self._check_allowed_dtypes(other, "integer", "__lshift__")
797796
if other is NotImplemented:
798797
return other
799-
self, other = self._normalize_two_args(self, other)
800-
res = self._array.__lshift__(other._array)
798+
_self, other = self._normalize_two_args(self, other)
799+
res = _self._array.__lshift__(other._array)
801800
return self.__class__._new(res, device=self.device)
802801

803802
def __lt__(self, other: Array | float, /) -> Array:
@@ -808,8 +807,8 @@ def __lt__(self, other: Array | float, /) -> Array:
808807
other = self._check_allowed_dtypes(other, "real numeric", "__lt__")
809808
if other is NotImplemented:
810809
return other
811-
self, other = self._normalize_two_args(self, other)
812-
res = self._array.__lt__(other._array)
810+
_self, other = self._normalize_two_args(self, other)
811+
res = _self._array.__lt__(other._array)
813812
return self.__class__._new(res, device=self.device)
814813

815814
def __matmul__(self, other: Array, /) -> Array:
@@ -833,8 +832,8 @@ def __mod__(self, other: Array | float, /) -> Array:
833832
other = self._check_allowed_dtypes(other, "real numeric", "__mod__")
834833
if other is NotImplemented:
835834
return other
836-
self, other = self._normalize_two_args(self, other)
837-
res = self._array.__mod__(other._array)
835+
_self, other = self._normalize_two_args(self, other)
836+
res = _self._array.__mod__(other._array)
838837
return self.__class__._new(res, device=self.device)
839838

840839
def __mul__(self, other: Array | complex, /) -> Array:
@@ -845,8 +844,8 @@ def __mul__(self, other: Array | complex, /) -> Array:
845844
other = self._check_allowed_dtypes(other, "numeric", "__mul__")
846845
if other is NotImplemented:
847846
return other
848-
self, other = self._normalize_two_args(self, other)
849-
res = self._array.__mul__(other._array)
847+
_self, other = self._normalize_two_args(self, other)
848+
res = _self._array.__mul__(other._array)
850849
return self.__class__._new(res, device=self.device)
851850

852851
def __ne__(self, other: Array | complex, /) -> Array: # type: ignore[override]
@@ -857,8 +856,8 @@ def __ne__(self, other: Array | complex, /) -> Array: # type: ignore[override]
857856
other = self._check_allowed_dtypes(other, "all", "__ne__")
858857
if other is NotImplemented:
859858
return other
860-
self, other = self._normalize_two_args(self, other)
861-
res = self._array.__ne__(other._array)
859+
_self, other = self._normalize_two_args(self, other)
860+
res = _self._array.__ne__(other._array)
862861
return self.__class__._new(res, device=self.device)
863862

864863
def __neg__(self) -> Array:
@@ -878,8 +877,8 @@ def __or__(self, other: Array | int, /) -> Array:
878877
other = self._check_allowed_dtypes(other, "integer or boolean", "__or__")
879878
if other is NotImplemented:
880879
return other
881-
self, other = self._normalize_two_args(self, other)
882-
res = self._array.__or__(other._array)
880+
_self, other = self._normalize_two_args(self, other)
881+
res = _self._array.__or__(other._array)
883882
return self.__class__._new(res, device=self.device)
884883

885884
def __pos__(self) -> Array:
@@ -913,8 +912,8 @@ def __rshift__(self, other: Array | int, /) -> Array:
913912
other = self._check_allowed_dtypes(other, "integer", "__rshift__")
914913
if other is NotImplemented:
915914
return other
916-
self, other = self._normalize_two_args(self, other)
917-
res = self._array.__rshift__(other._array)
915+
_self, other = self._normalize_two_args(self, other)
916+
res = _self._array.__rshift__(other._array)
918917
return self.__class__._new(res, device=self.device)
919918

920919
def __setitem__(
@@ -962,8 +961,8 @@ def __sub__(self, other: Array | complex, /) -> Array:
962961
other = self._check_allowed_dtypes(other, "numeric", "__sub__")
963962
if other is NotImplemented:
964963
return other
965-
self, other = self._normalize_two_args(self, other)
966-
res = self._array.__sub__(other._array)
964+
_self, other = self._normalize_two_args(self, other)
965+
res = _self._array.__sub__(other._array)
967966
return self.__class__._new(res, device=self.device)
968967

969968
# PEP 484 requires int to be a subtype of float, but __truediv__ should
@@ -976,8 +975,8 @@ def __truediv__(self, other: Array | complex, /) -> Array:
976975
other = self._check_allowed_dtypes(other, "floating-point", "__truediv__")
977976
if other is NotImplemented:
978977
return other
979-
self, other = self._normalize_two_args(self, other)
980-
res = self._array.__truediv__(other._array)
978+
_self, other = self._normalize_two_args(self, other)
979+
res = _self._array.__truediv__(other._array)
981980
return self.__class__._new(res, device=self.device)
982981

983982
def __xor__(self, other: Array | int, /) -> Array:
@@ -988,8 +987,8 @@ def __xor__(self, other: Array | int, /) -> Array:
988987
other = self._check_allowed_dtypes(other, "integer or boolean", "__xor__")
989988
if other is NotImplemented:
990989
return other
991-
self, other = self._normalize_two_args(self, other)
992-
res = self._array.__xor__(other._array)
990+
_self, other = self._normalize_two_args(self, other)
991+
res = _self._array.__xor__(other._array)
993992
return self.__class__._new(res, device=self.device)
994993

995994
def __iadd__(self, other: Array | complex, /) -> Self:
@@ -1011,8 +1010,8 @@ def __radd__(self, other: Array | complex, /) -> Array:
10111010
other = self._check_allowed_dtypes(other, "numeric", "__radd__")
10121011
if other is NotImplemented:
10131012
return other
1014-
self, other = self._normalize_two_args(self, other)
1015-
res = self._array.__radd__(other._array)
1013+
_self, other = self._normalize_two_args(self, other)
1014+
res = _self._array.__radd__(other._array)
10161015
return self.__class__._new(res, device=self.device)
10171016

10181017
def __iand__(self, other: Array | int, /) -> Self:
@@ -1034,8 +1033,8 @@ def __rand__(self, other: Array | int, /) -> Array:
10341033
other = self._check_allowed_dtypes(other, "integer or boolean", "__rand__")
10351034
if other is NotImplemented:
10361035
return other
1037-
self, other = self._normalize_two_args(self, other)
1038-
res = self._array.__rand__(other._array)
1036+
_self, other = self._normalize_two_args(self, other)
1037+
res = _self._array.__rand__(other._array)
10391038
return self.__class__._new(res, device=self.device)
10401039

10411040
def __ifloordiv__(self, other: Array | float, /) -> Self:
@@ -1057,8 +1056,8 @@ def __rfloordiv__(self, other: Array | float, /) -> Array:
10571056
other = self._check_allowed_dtypes(other, "real numeric", "__rfloordiv__")
10581057
if other is NotImplemented:
10591058
return other
1060-
self, other = self._normalize_two_args(self, other)
1061-
res = self._array.__rfloordiv__(other._array)
1059+
_self, other = self._normalize_two_args(self, other)
1060+
res = _self._array.__rfloordiv__(other._array)
10621061
return self.__class__._new(res, device=self.device)
10631062

10641063
def __ilshift__(self, other: Array | int, /) -> Self:
@@ -1080,8 +1079,8 @@ def __rlshift__(self, other: Array | int, /) -> Array:
10801079
other = self._check_allowed_dtypes(other, "integer", "__rlshift__")
10811080
if other is NotImplemented:
10821081
return other
1083-
self, other = self._normalize_two_args(self, other)
1084-
res = self._array.__rlshift__(other._array)
1082+
_self, other = self._normalize_two_args(self, other)
1083+
res = _self._array.__rlshift__(other._array)
10851084
return self.__class__._new(res, device=self.device)
10861085

10871086
def __imatmul__(self, other: Array, /) -> Self:
@@ -1129,8 +1128,8 @@ def __rmod__(self, other: Array | float, /) -> Array:
11291128
if other is NotImplemented:
11301129
return other
11311130
self._check_type_device(other)
1132-
self, other = self._normalize_two_args(self, other)
1133-
res = self._array.__rmod__(other._array)
1131+
_self, other = self._normalize_two_args(self, other)
1132+
res = _self._array.__rmod__(other._array)
11341133
return self.__class__._new(res, device=self.device)
11351134

11361135
def __imul__(self, other: Array | complex, /) -> Self:
@@ -1152,8 +1151,8 @@ def __rmul__(self, other: Array | complex, /) -> Array:
11521151
if other is NotImplemented:
11531152
return other
11541153
self._check_type_device(other)
1155-
self, other = self._normalize_two_args(self, other)
1156-
res = self._array.__rmul__(other._array)
1154+
_self, other = self._normalize_two_args(self, other)
1155+
res = _self._array.__rmul__(other._array)
11571156
return self.__class__._new(res, device=self.device)
11581157

11591158
def __ior__(self, other: Array | int, /) -> Self:
@@ -1175,8 +1174,8 @@ def __ror__(self, other: Array | int, /) -> Array:
11751174
other = self._check_allowed_dtypes(other, "integer or boolean", "__ror__")
11761175
if other is NotImplemented:
11771176
return other
1178-
self, other = self._normalize_two_args(self, other)
1179-
res = self._array.__ror__(other._array)
1177+
_self, other = self._normalize_two_args(self, other)
1178+
res = _self._array.__ror__(other._array)
11801179
return self.__class__._new(res, device=self.device)
11811180

11821181
def __ipow__(self, other: Array | complex, /) -> Self:
@@ -1223,8 +1222,8 @@ def __rrshift__(self, other: Array | int, /) -> Array:
12231222
if other is NotImplemented:
12241223
return other
12251224
self._check_type_device(other)
1226-
self, other = self._normalize_two_args(self, other)
1227-
res = self._array.__rrshift__(other._array)
1225+
_self, other = self._normalize_two_args(self, other)
1226+
res = _self._array.__rrshift__(other._array)
12281227
return self.__class__._new(res, device=self.device)
12291228

12301229
def __isub__(self, other: Array | complex, /) -> Self:
@@ -1246,8 +1245,8 @@ def __rsub__(self, other: Array | complex, /) -> Array:
12461245
if other is NotImplemented:
12471246
return other
12481247
self._check_type_device(other)
1249-
self, other = self._normalize_two_args(self, other)
1250-
res = self._array.__rsub__(other._array)
1248+
_self, other = self._normalize_two_args(self, other)
1249+
res = _self._array.__rsub__(other._array)
12511250
return self.__class__._new(res, device=self.device)
12521251

12531252
def __itruediv__(self, other: Array | complex, /) -> Self:
@@ -1269,8 +1268,8 @@ def __rtruediv__(self, other: Array | complex, /) -> Array:
12691268
if other is NotImplemented:
12701269
return other
12711270
self._check_type_device(other)
1272-
self, other = self._normalize_two_args(self, other)
1273-
res = self._array.__rtruediv__(other._array)
1271+
_self, other = self._normalize_two_args(self, other)
1272+
res = _self._array.__rtruediv__(other._array)
12741273
return self.__class__._new(res, device=self.device)
12751274

12761275
def __ixor__(self, other: Array | int, /) -> Self:
@@ -1292,8 +1291,8 @@ def __rxor__(self, other: Array | int, /) -> Array:
12921291
if other is NotImplemented:
12931292
return other
12941293
self._check_type_device(other)
1295-
self, other = self._normalize_two_args(self, other)
1296-
res = self._array.__rxor__(other._array)
1294+
_self, other = self._normalize_two_args(self, other)
1295+
res = _self._array.__rxor__(other._array)
12971296
return self.__class__._new(res, device=self.device)
12981297

12991298
def to_device(self, device: Device, /, stream: None = None) -> Array:

‎array_api_strict/_manipulation_functions.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def roll(
142142
See its docstring for more information.
143143
"""
144144
if not isinstance(shift, int | tuple):
145-
raise ValueError(
145+
raise TypeError(
146146
f"`shift` can only be an int or a tuple, got {type(shift)=} instead."
147147
)
148148
return Array._new(np.roll(x._array, shift, axis=axis), device=x.device)

0 commit comments

Comments
 (0)