Skip to content

Commit a0efa5c

Browse files
Merge pull request #416 from DimitriPapadopoulos/ruff
MAINT: Enforce additional ruff rules
1 parent a506e9c commit a0efa5c

File tree

9 files changed

+34
-25
lines changed

9 files changed

+34
-25
lines changed

array_api_compat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
"""
2020
__version__ = '1.15.0.dev0'
2121

22-
from .common import * # noqa: F401, F403
22+
from .common import * # noqa: F403

array_api_compat/common/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def your_function(x, y):
669669
# torch._dynamo.exc.Unsupported: Dynamo cannot determine whether the underlying object is hashable
670670
# Explanation: Dynamo does not know whether the underlying python object for
671671
# PythonModuleVariable(<module 'array_api_compat.torch' from ...) is hashable
672-
names = set(x.__name__ for x in namespaces)
672+
names = {x.__name__ for x in namespaces}
673673
unique_namespaces = []
674674
for ns in namespaces:
675675
if (name := ns.__name__) in names:

array_api_compat/cupy/linalg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
__all__ = linalg_all + _linalg.__all__
5757

5858
# cupy 13 does not have __all__, cupy 14 has it: remove duplicates
59-
__all__ = sorted(list(set(__all__)))
59+
__all__ = sorted(set(__all__))
6060

6161
def __dir__() -> list[str]:
6262
return __all__

array_api_compat/numpy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# ruff: noqa: PLC0414
21
from typing import Final
32

43
from .._internal import clone_module

array_api_compat/torch/_aliases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def _axis_none_keepdims(x, ndim, keepdims):
278278
# (https://github.com/pytorch/pytorch/issues/71209)
279279
# Note that this is only valid for the axis=None case.
280280
if keepdims:
281-
for i in range(ndim):
281+
for _ in range(ndim):
282282
x = torch.unsqueeze(x, 0)
283283
return x
284284

array_api_compat/torch/fft.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def fftn(
1717
x: Array,
1818
/,
1919
*,
20-
s: Sequence[int] = None,
21-
axes: Sequence[int] = None,
20+
s: Sequence[int] | None = None,
21+
axes: Sequence[int] | None = None,
2222
norm: Literal["backward", "ortho", "forward"] = "backward",
2323
**kwargs: object,
2424
) -> Array:
@@ -28,8 +28,8 @@ def ifftn(
2828
x: Array,
2929
/,
3030
*,
31-
s: Sequence[int] = None,
32-
axes: Sequence[int] = None,
31+
s: Sequence[int] | None = None,
32+
axes: Sequence[int] | None = None,
3333
norm: Literal["backward", "ortho", "forward"] = "backward",
3434
**kwargs: object,
3535
) -> Array:
@@ -39,8 +39,8 @@ def rfftn(
3939
x: Array,
4040
/,
4141
*,
42-
s: Sequence[int] = None,
43-
axes: Sequence[int] = None,
42+
s: Sequence[int] | None = None,
43+
axes: Sequence[int] | None = None,
4444
norm: Literal["backward", "ortho", "forward"] = "backward",
4545
**kwargs: object,
4646
) -> Array:
@@ -50,8 +50,8 @@ def irfftn(
5050
x: Array,
5151
/,
5252
*,
53-
s: Sequence[int] = None,
54-
axes: Sequence[int] = None,
53+
s: Sequence[int] | None = None,
54+
axes: Sequence[int] | None = None,
5555
norm: Literal["backward", "ortho", "forward"] = "backward",
5656
**kwargs: object,
5757
) -> Array:
@@ -61,7 +61,7 @@ def fftshift(
6161
x: Array,
6262
/,
6363
*,
64-
axes: int | Sequence[int] = None,
64+
axes: int | Sequence[int] | None = None,
6565
**kwargs: object,
6666
) -> Array:
6767
return torch.fft.fftshift(x, dim=axes, **kwargs)
@@ -70,7 +70,7 @@ def ifftshift(
7070
x: Array,
7171
/,
7272
*,
73-
axes: int | Sequence[int] = None,
73+
axes: int | Sequence[int] | None = None,
7474
**kwargs: object,
7575
) -> Array:
7676
return torch.fft.ifftshift(x, dim=axes, **kwargs)

pyproject.toml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,29 @@ namespaces = false
6565
[tool.ruff.lint]
6666
preview = true
6767
select = [
68-
# Defaults
69-
"E4", "E7", "E9", "F",
70-
# Undefined export
71-
"F822",
72-
# Useless import alias
73-
"PLC0414"
68+
# Defaults
69+
"E4", "E7", "E9", "F",
70+
# Additional rules
71+
"B", "C4", "ISC", "PIE", "FLY", "PERF", "UP", "FURB",
72+
# Useless import alias
73+
"PLC0414",
74+
# Unused `noqa` directive
75+
"RUF100",
7476
]
7577

7678
ignore = [
7779
# Module import not at top of file
7880
"E402",
7981
# Do not use bare `except`
80-
"E722"
82+
"E722",
83+
# Use of `functools.cache` on methods can lead to memory leaks
84+
"B019",
85+
# No explicit `stacklevel` keyword argument found
86+
"B028",
87+
# Within an `except` clause, raise exceptions with `raise ... from ...`
88+
"B904",
89+
# `try`-`except` within a loop incurs performance overhead
90+
"PERF203",
8191
]
8292

8393

tests/test_isdtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def isdtype_(dtype_, kind):
6161
res = dtype_categories[kind](dtype_)
6262
else:
6363
res = dtype_ == kind
64-
assert type(res) is bool # noqa: E721
64+
assert type(res) is bool
6565
return res
6666

6767
@pytest.mark.parametrize("library", wrapped_libraries)

tests/test_no_dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def _test_dependency(mod):
3838
assert not is_mod_array(a)
3939
assert mod not in sys.modules
4040

41-
is_array_api_obj = getattr(array_api_compat, "is_array_api_obj")
41+
is_array_api_obj = array_api_compat.is_array_api_obj
4242
assert is_array_api_obj(a)
4343
assert mod not in sys.modules
4444

45-
array_namespace = getattr(array_api_compat, "array_namespace")
45+
array_namespace = array_api_compat.array_namespace
4646
array_namespace(Array())
4747
assert mod not in sys.modules
4848

0 commit comments

Comments
 (0)