Skip to content

Commit c273dc8

Browse files
committed
Replace exception suppression with python version checking
1 parent 6376080 commit c273dc8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

eitprocessing/datahandling/sequence.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
import contextlib
43
import itertools
4+
import sys
55
from dataclasses import MISSING, dataclass, field
66
from typing import TYPE_CHECKING, Any, TypeVar, overload
77

@@ -208,10 +208,11 @@ def __post_init__(self):
208208
if duplicates := set(a) & set(b):
209209
msg = f"Duplicate labels ({', '.join(sorted(duplicates))}) found in {a} and {b}."
210210
exc = KeyError(msg)
211-
with contextlib.suppress(AttributeError):
211+
if sys.version_info >= (3, 11):
212212
exc.add_note(
213213
"You can't use the `data` interface with duplicate labels. "
214-
"Use the explicit data collections (`eit_data`, `continuous_data`, `sparse_data`, `interval_data`) instead."
214+
"Use the explicit data collections (`eit_data`, `continuous_data`, `sparse_data`, "
215+
"`interval_data`) instead."
215216
)
216217
raise exc
217218

@@ -282,10 +283,11 @@ def add(self, *obj: DataContainer) -> None:
282283
if self.get(object_.label, None):
283284
msg = f"An object with the label {object_.label} already exists in this sequence."
284285
exc = KeyError(msg)
285-
with contextlib.suppress(AttributeError):
286+
if sys.version_info >= (3, 11):
286287
exc.add_note(
287288
"You can't add an object with the same label through the `data` interface. "
288-
"Use the explicit data collections (`eit_data`, `continuous_data`, `sparse_data`, `interval_data`) instead."
289+
"Use the explicit data collections (`eit_data`, `continuous_data`, `sparse_data`, "
290+
"`interval_data`) instead."
289291
)
290292
raise exc
291293

0 commit comments

Comments
 (0)