Skip to content

Commit ca2e6b4

Browse files
committed
user defined exceptions no longer inherit from KeyError
1 parent 23cd622 commit ca2e6b4

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/stagpy/_caching.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from functools import cached_property
99

1010
from . import phyvars, stagyyparsers
11+
from .error import InvalidSnapshotError
1112

1213
if typing.TYPE_CHECKING:
1314
from collections.abc import Mapping
@@ -169,7 +170,7 @@ def isnap(self, *, istep: int) -> int | None:
169170
isnap += 1
170171
try:
171172
istep_try = self.sdat.snaps[isnap].istep
172-
except KeyError:
173+
except InvalidSnapshotError:
173174
pass
174175
# all intermediate istep could have their isnap to None
175176
self._snap_to_step[isnap] = istep_try

src/stagpy/error.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self, file: PathLike, msg: str):
9999
super().__init__(file, msg)
100100

101101

102-
class InvalidTimestepError(StagpyError, KeyError):
102+
class InvalidTimestepError(StagpyError):
103103
"""Raised when invalid time step is requested.
104104
105105
Attributes:
@@ -115,7 +115,7 @@ def __init__(self, sdat: StagyyData, istep: int, msg: str):
115115
super().__init__(sdat, istep, msg)
116116

117117

118-
class InvalidSnapshotError(StagpyError, KeyError):
118+
class InvalidSnapshotError(StagpyError):
119119
"""Raised when invalid snapshot is requested.
120120
121121
Attributes:
@@ -167,11 +167,11 @@ def __init__(self, zoom: float):
167167
super().__init__(f"Zoom angle should be in [0,360] (received {zoom})")
168168

169169

170-
class MissingDataError(StagpyError, KeyError):
170+
class MissingDataError(StagpyError):
171171
"""Raised when requested data is not present in output."""
172172

173173

174-
class UnknownVarError(StagpyError, KeyError):
174+
class UnknownVarError(StagpyError):
175175
"""Raised when invalid var is requested.
176176
177177
Attributes:

src/stagpy/stagyydata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def _pass(self, item: int) -> bool:
568568
"""Check whether an item passes the filters."""
569569
try:
570570
step = self.over[item]
571-
except KeyError:
571+
except (error.InvalidTimestepError, error.InvalidSnapshotError):
572572
return False
573573
return self.filters.passes(step)
574574

0 commit comments

Comments
 (0)