Skip to content

Enable ruff/flake8-raise rules (RSE) and fix issues #1866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Docs
Maintenance
~~~~~~~~~~~

* Enable ruff/flake8-raise rules (RSE) and fix issues.
By :user:`Dimitri Papadopoulos Orfanos <DimitriPapadopoulos>` :issue:`1704`.

Deprecations
~~~~~~~~~~~~

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ exclude = [

[tool.ruff.lint]
extend-select = [
"B"
"B",
"RSE"
]

[tool.black]
Expand Down
6 changes: 3 additions & 3 deletions zarr/_storage/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def getsize(self, path=None):

def setitems(self, values):
if self.mode == "r":
raise ReadOnlyError()
raise ReadOnlyError
values = {self._normalize_key(key): val for key, val in values.items()}

# initialize the /data/root/... folder corresponding to the array!
Expand All @@ -175,7 +175,7 @@ def setitems(self, values):

def rmdir(self, path=None):
if self.mode == "r":
raise ReadOnlyError()
raise ReadOnlyError
if path:
for base in [meta_root, data_root]:
store_path = self.dir_path(base + path)
Expand Down Expand Up @@ -579,7 +579,7 @@ def __init__(self, store: StoreLike, metadata_key=meta_root + "consolidated/.zme
self.meta_store: Store = KVStoreV3(meta["metadata"])

def rmdir(self, key):
raise ReadOnlyError()
raise ReadOnlyError


def _normalize_store_arg_v3(store: Any, storage_options=None, mode="r") -> BaseStore:
Expand Down
12 changes: 6 additions & 6 deletions zarr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,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 @@ -1627,7 +1627,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 @@ -1700,7 +1700,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 @@ -1793,7 +1793,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 @@ -1869,7 +1869,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 @@ -2588,7 +2588,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 zarr/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,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 zarr/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,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 @@ -977,7 +977,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 zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,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 @@ -1460,7 +1460,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 @@ -1474,7 +1474,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 @@ -1484,7 +1484,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 @@ -1543,7 +1543,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 @@ -1554,7 +1554,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 @@ -1865,7 +1865,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 @@ -1947,7 +1947,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 @@ -3068,10 +3068,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 zarr/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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