Skip to content

Commit

Permalink
Enable ruff/flake8-raise rules (RSE) and fix issues (#1872)
Browse files Browse the repository at this point in the history
* Enable ruff/flake8-raise rules (RSE)

* Apply ruff/flake8-raise rule RSE102

RSE102 Unnecessary parentheses on raised exception
  • Loading branch information
DimitriPapadopoulos authored May 17, 2024
1 parent ea2da93 commit 333f37f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ extend-select = [
"B", # flake8-bugbear
"I", # isort
"UP", # pyupgrade
"RSE",
"RUF",
]
ignore = [
Expand Down
12 changes: 6 additions & 6 deletions src/zarr/v2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/zarr/v2/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/v2/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/zarr/v2/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -1380,7 +1380,7 @@ def getsize(self, path=None):

def clear(self):
if self.mode == "r":
raise ReadOnlyError()
raise ReadOnlyError
self.map.clear()

@classmethod
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/v3/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def parse_store(
return MemoryStore()
if store == "remote":
return RemoteStore()
raise AssertionError()
raise AssertionError


@pytest.fixture(params=[str, pathlib.Path])
Expand Down
6 changes: 3 additions & 3 deletions tests/v3/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand All @@ -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"])
Expand Down

0 comments on commit 333f37f

Please sign in to comment.