diff --git a/pyproject.toml b/pyproject.toml index 1aafb64a2b..4fb90c7496 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -170,6 +170,7 @@ extend-select = [ "B", # flake8-bugbear "I", # isort "UP", # pyupgrade + "RSE", "RUF", ] ignore = [ diff --git a/src/zarr/v2/core.py b/src/zarr/v2/core.py index 273d2857e8..c1223daced 100644 --- a/src/zarr/v2/core.py +++ b/src/zarr/v2/core.py @@ -1465,7 +1465,7 @@ def set_basic_selection(self, selection, value, fields=None): # guard conditions if self._read_only: - raise ReadOnlyError() + raise ReadOnlyError # refresh metadata if not self._cache_metadata: @@ -1557,7 +1557,7 @@ def set_orthogonal_selection(self, selection, value, fields=None): # guard conditions if self._read_only: - raise ReadOnlyError() + raise ReadOnlyError # refresh metadata if not self._cache_metadata: @@ -1630,7 +1630,7 @@ def set_coordinate_selection(self, selection, value, fields=None): # guard conditions if self._read_only: - raise ReadOnlyError() + raise ReadOnlyError # refresh metadata if not self._cache_metadata: @@ -1723,7 +1723,7 @@ def set_block_selection(self, selection, value, fields=None): """ # guard conditions if self._read_only: - raise ReadOnlyError() + raise ReadOnlyError # refresh metadata if not self._cache_metadata: @@ -1799,7 +1799,7 @@ def set_mask_selection(self, selection, value, fields=None): # guard conditions if self._read_only: - raise ReadOnlyError() + raise ReadOnlyError # refresh metadata if not self._cache_metadata: @@ -2489,7 +2489,7 @@ def _synchronized_op(self, f, *args, **kwargs): def _write_op(self, f, *args, **kwargs): # guard condition if self._read_only: - raise ReadOnlyError() + raise ReadOnlyError return self._synchronized_op(f, *args, **kwargs) diff --git a/src/zarr/v2/hierarchy.py b/src/zarr/v2/hierarchy.py index acd65750e3..b0660d181d 100644 --- a/src/zarr/v2/hierarchy.py +++ b/src/zarr/v2/hierarchy.py @@ -797,7 +797,7 @@ def tree(self, expand=False, level=None): def _write_op(self, f, *args, **kwargs): # guard condition if self._read_only: - raise ReadOnlyError() + raise ReadOnlyError if self._synchronizer is None: # no synchronization diff --git a/src/zarr/v2/indexing.py b/src/zarr/v2/indexing.py index 1c11409d05..7b9b74d227 100644 --- a/src/zarr/v2/indexing.py +++ b/src/zarr/v2/indexing.py @@ -170,7 +170,7 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len): # normalize self.start, self.stop, self.step = dim_sel.indices(dim_len) if self.step < 1: - raise NegativeStepError() + raise NegativeStepError # store attributes self.dim_len = dim_len @@ -978,7 +978,7 @@ def make_slice_selection(selection): if len(dim_selection) == 1: ls.append(slice(int(dim_selection[0]), int(dim_selection[0]) + 1, 1)) else: - raise ArrayIndexError() + raise ArrayIndexError else: ls.append(dim_selection) return ls diff --git a/src/zarr/v2/storage.py b/src/zarr/v2/storage.py index de45201fc0..67240e520d 100644 --- a/src/zarr/v2/storage.py +++ b/src/zarr/v2/storage.py @@ -1275,7 +1275,7 @@ def __getitem__(self, key): def setitems(self, values): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError # Normalize keys and make sure the values are bytes values = { @@ -1286,7 +1286,7 @@ def setitems(self, values): def __setitem__(self, key, value): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError key = self._normalize_key(key) value = ensure_contiguous_ndarray_or_bytes(value) path = self.dir_path(key) @@ -1300,7 +1300,7 @@ def __setitem__(self, key, value): def __delitem__(self, key): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError key = self._normalize_key(key) path = self.dir_path(key) if self.fs.isdir(path): @@ -1310,7 +1310,7 @@ def __delitem__(self, key): def delitems(self, keys): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError # only remove the keys that exist in the store nkeys = [self._normalize_key(key) for key in keys if key in self] # rm errors if you pass an empty collection @@ -1369,7 +1369,7 @@ def listdir(self, path=None): def rmdir(self, path=None): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError store_path = self.dir_path(path) if self.fs.isdir(store_path): self.fs.rm(store_path, recursive=True) @@ -1380,7 +1380,7 @@ def getsize(self, path=None): def clear(self): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError self.map.clear() @classmethod @@ -1670,7 +1670,7 @@ def __getitem__(self, key): def __setitem__(self, key, value): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError value = ensure_contiguous_ndarray_like(value).view("u1") with self.mutex: # writestr(key, value) writes with default permissions from @@ -1752,7 +1752,7 @@ def getsize(self, path=None): def clear(self): if self.mode == "r": - raise ReadOnlyError() + raise ReadOnlyError with self.mutex: self.close() os.remove(self.path) @@ -2810,10 +2810,10 @@ def __len__(self): return len(self.meta_store) def __delitem__(self, key): - raise ReadOnlyError() + raise ReadOnlyError def __setitem__(self, key, value): - raise ReadOnlyError() + raise ReadOnlyError def getsize(self, path): return getsize(self.meta_store, path) diff --git a/tests/v2/test_util.py b/tests/v2/test_util.py index 35c355693a..0111165df9 100644 --- a/tests/v2/test_util.py +++ b/tests/v2/test_util.py @@ -210,7 +210,7 @@ def __init__(self, pass_on=1): def __call__(self): self.c += 1 if self.c != self.pass_on: - raise PermissionError() + raise PermissionError for x in range(1, 11): # Any number of failures less than 10 will be accepted. diff --git a/tests/v3/conftest.py b/tests/v3/conftest.py index b6a121520d..b9f56014bc 100644 --- a/tests/v3/conftest.py +++ b/tests/v3/conftest.py @@ -25,7 +25,7 @@ def parse_store( return MemoryStore() if store == "remote": return RemoteStore() - raise AssertionError() + raise AssertionError @pytest.fixture(params=[str, pathlib.Path]) diff --git a/tests/v3/test_group.py b/tests/v3/test_group.py index 771baddc0b..36b82f413c 100644 --- a/tests/v3/test_group.py +++ b/tests/v3/test_group.py @@ -203,7 +203,7 @@ async def test_asyncgroup_open_wrong_format( elif zarr_format == 2: zarr_format_wrong = 3 else: - raise AssertionError() + raise AssertionError with pytest.raises(FileNotFoundError): await AsyncGroup.open(store=store, zarr_format=zarr_format_wrong) @@ -278,7 +278,7 @@ async def test_asyncgroup_delitem(store: LocalStore | MemoryStore, zarr_format: elif zarr_format == 3: assert not await agroup.store_path.store.exists(sub_array_path + "/" + "zarr.json") else: - raise AssertionError() + raise AssertionError sub_group_path = "sub_group" _ = await agroup.create_group(sub_group_path, attributes={"foo": 100}) @@ -289,7 +289,7 @@ async def test_asyncgroup_delitem(store: LocalStore | MemoryStore, zarr_format: elif zarr_format == 3: assert not await agroup.store_path.store.exists(sub_array_path + "/" + "zarr.json") else: - raise AssertionError() + raise AssertionError @pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])