Skip to content

Commit c5f9a62

Browse files
committed
Change inheritance of errors so Group and Array inherit from Node
1 parent 22c9663 commit c5f9a62

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/zarr/errors.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import Any
22

3-
from typing_extensions import deprecated
4-
53
__all__ = [
64
"ArrayNotFoundError",
75
"BaseZarrError",
@@ -29,15 +27,22 @@ def __init__(self, *args: Any) -> None:
2927
super().__init__(self._msg.format(*args))
3028

3129

32-
class GroupNotFoundError(BaseZarrError, FileNotFoundError):
30+
class NodeNotFoundError(BaseZarrError, FileNotFoundError):
3331
"""
34-
Raised when a group isn't found at a certain path.
32+
Raised when a node (array or group) is not found at a certain path.
3533
"""
3634

37-
_msg = "No group found in store {!r} at path {!r}"
35+
def __init__(self, *args: Any) -> None:
36+
if len(args) == 1:
37+
# Pre-formatted message
38+
super(BaseZarrError, self).__init__(args[0])
39+
else:
40+
# Store and path arguments - format them
41+
_msg = "No node found in store {!r} at path {!r}"
42+
super(BaseZarrError, self).__init__(_msg.format(*args))
3843

3944

40-
class ArrayNotFoundError(BaseZarrError, FileNotFoundError):
45+
class ArrayNotFoundError(NodeNotFoundError):
4146
"""
4247
Raised when an array isn't found at a certain path.
4348
"""
@@ -52,14 +57,19 @@ def __init__(self, *args: Any) -> None:
5257
super(BaseZarrError, self).__init__(_msg.format(*args))
5358

5459

55-
@deprecated("Use NodeNotFoundError instead.", category=None)
56-
class PathNotFoundError(BaseZarrError):
57-
# Backwards compatibility with v2. Superseded by NodeNotFoundError.
58-
...
59-
60+
class GroupNotFoundError(NodeNotFoundError):
61+
"""
62+
Raised when a group isn't found at a certain path.
63+
"""
6064

61-
class NodeNotFoundError(PathNotFoundError):
62-
"""Raised when an array or group does not exist at a certain path."""
65+
def __init__(self, *args: Any) -> None:
66+
if len(args) == 1:
67+
# Pre-formatted message
68+
super(BaseZarrError, self).__init__(args[0])
69+
else:
70+
# Store and path arguments - format them
71+
_msg = "No group found in store {!r} at path {!r}"
72+
super(BaseZarrError, self).__init__(_msg.format(*args))
6373

6474

6575
class ContainsGroupError(BaseZarrError):

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) ->
192192
assert z.read_only
193193

194194
# path not found
195-
with pytest.raises((NodeNotFoundError, GroupNotFoundError)):
195+
with pytest.raises(NodeNotFoundError):
196196
zarr.api.synchronous.open(store="doesnotexist", mode="r", zarr_format=zarr_format)
197197

198198

0 commit comments

Comments
 (0)