diff --git a/array_api_compat/__init__.py b/array_api_compat/__init__.py index e7480cce..454c7f8b 100644 --- a/array_api_compat/__init__.py +++ b/array_api_compat/__init__.py @@ -19,4 +19,4 @@ """ __version__ = '1.15.0.dev0' -from .common import * # noqa: F401, F403 +from .common import * # noqa: F403 diff --git a/array_api_compat/common/_helpers.py b/array_api_compat/common/_helpers.py index b43e3d22..c154ad0b 100644 --- a/array_api_compat/common/_helpers.py +++ b/array_api_compat/common/_helpers.py @@ -669,7 +669,7 @@ def your_function(x, y): # torch._dynamo.exc.Unsupported: Dynamo cannot determine whether the underlying object is hashable # Explanation: Dynamo does not know whether the underlying python object for # PythonModuleVariable( list[str]: return __all__ diff --git a/array_api_compat/numpy/__init__.py b/array_api_compat/numpy/__init__.py index bda4356f..973e993d 100644 --- a/array_api_compat/numpy/__init__.py +++ b/array_api_compat/numpy/__init__.py @@ -1,4 +1,3 @@ -# ruff: noqa: PLC0414 from typing import Final from .._internal import clone_module diff --git a/array_api_compat/torch/_aliases.py b/array_api_compat/torch/_aliases.py index 88936302..5969e4db 100644 --- a/array_api_compat/torch/_aliases.py +++ b/array_api_compat/torch/_aliases.py @@ -278,7 +278,7 @@ def _axis_none_keepdims(x, ndim, keepdims): # (https://github.com/pytorch/pytorch/issues/71209) # Note that this is only valid for the axis=None case. if keepdims: - for i in range(ndim): + for _ in range(ndim): x = torch.unsqueeze(x, 0) return x diff --git a/array_api_compat/torch/fft.py b/array_api_compat/torch/fft.py index f11b3eb5..0fa6ea9a 100644 --- a/array_api_compat/torch/fft.py +++ b/array_api_compat/torch/fft.py @@ -17,8 +17,8 @@ def fftn( x: Array, /, *, - s: Sequence[int] = None, - axes: Sequence[int] = None, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, norm: Literal["backward", "ortho", "forward"] = "backward", **kwargs: object, ) -> Array: @@ -28,8 +28,8 @@ def ifftn( x: Array, /, *, - s: Sequence[int] = None, - axes: Sequence[int] = None, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, norm: Literal["backward", "ortho", "forward"] = "backward", **kwargs: object, ) -> Array: @@ -39,8 +39,8 @@ def rfftn( x: Array, /, *, - s: Sequence[int] = None, - axes: Sequence[int] = None, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, norm: Literal["backward", "ortho", "forward"] = "backward", **kwargs: object, ) -> Array: @@ -50,8 +50,8 @@ def irfftn( x: Array, /, *, - s: Sequence[int] = None, - axes: Sequence[int] = None, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, norm: Literal["backward", "ortho", "forward"] = "backward", **kwargs: object, ) -> Array: @@ -61,7 +61,7 @@ def fftshift( x: Array, /, *, - axes: int | Sequence[int] = None, + axes: int | Sequence[int] | None = None, **kwargs: object, ) -> Array: return torch.fft.fftshift(x, dim=axes, **kwargs) @@ -70,7 +70,7 @@ def ifftshift( x: Array, /, *, - axes: int | Sequence[int] = None, + axes: int | Sequence[int] | None = None, **kwargs: object, ) -> Array: return torch.fft.ifftshift(x, dim=axes, **kwargs) diff --git a/pyproject.toml b/pyproject.toml index 073074ca..d7339170 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,19 +65,29 @@ namespaces = false [tool.ruff.lint] preview = true select = [ -# Defaults -"E4", "E7", "E9", "F", -# Undefined export -"F822", -# Useless import alias -"PLC0414" + # Defaults + "E4", "E7", "E9", "F", + # Additional rules + "B", "C4", "ISC", "PIE", "FLY", "PERF", "UP", "FURB", + # Useless import alias + "PLC0414", + # Unused `noqa` directive + "RUF100", ] ignore = [ # Module import not at top of file "E402", # Do not use bare `except` - "E722" + "E722", + # Use of `functools.cache` on methods can lead to memory leaks + "B019", + # No explicit `stacklevel` keyword argument found + "B028", + # Within an `except` clause, raise exceptions with `raise ... from ...` + "B904", + # `try`-`except` within a loop incurs performance overhead + "PERF203", ] diff --git a/tests/test_isdtype.py b/tests/test_isdtype.py index 6ad45d4c..92e45613 100644 --- a/tests/test_isdtype.py +++ b/tests/test_isdtype.py @@ -61,7 +61,7 @@ def isdtype_(dtype_, kind): res = dtype_categories[kind](dtype_) else: res = dtype_ == kind - assert type(res) is bool # noqa: E721 + assert type(res) is bool return res @pytest.mark.parametrize("library", wrapped_libraries) diff --git a/tests/test_no_dependencies.py b/tests/test_no_dependencies.py index c53780b2..624f8971 100644 --- a/tests/test_no_dependencies.py +++ b/tests/test_no_dependencies.py @@ -38,11 +38,11 @@ def _test_dependency(mod): assert not is_mod_array(a) assert mod not in sys.modules - is_array_api_obj = getattr(array_api_compat, "is_array_api_obj") + is_array_api_obj = array_api_compat.is_array_api_obj assert is_array_api_obj(a) assert mod not in sys.modules - array_namespace = getattr(array_api_compat, "array_namespace") + array_namespace = array_api_compat.array_namespace array_namespace(Array()) assert mod not in sys.modules