|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import contextlib |
4 | 3 | import itertools |
| 4 | +import sys |
5 | 5 | from dataclasses import MISSING, dataclass, field |
6 | 6 | from typing import TYPE_CHECKING, Any, TypeVar, overload |
7 | 7 |
|
@@ -208,10 +208,11 @@ def __post_init__(self): |
208 | 208 | if duplicates := set(a) & set(b): |
209 | 209 | msg = f"Duplicate labels ({', '.join(sorted(duplicates))}) found in {a} and {b}." |
210 | 210 | exc = KeyError(msg) |
211 | | - with contextlib.suppress(AttributeError): |
| 211 | + if sys.version_info >= (3, 11): |
212 | 212 | exc.add_note( |
213 | 213 | "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." |
215 | 216 | ) |
216 | 217 | raise exc |
217 | 218 |
|
@@ -282,10 +283,11 @@ def add(self, *obj: DataContainer) -> None: |
282 | 283 | if self.get(object_.label, None): |
283 | 284 | msg = f"An object with the label {object_.label} already exists in this sequence." |
284 | 285 | exc = KeyError(msg) |
285 | | - with contextlib.suppress(AttributeError): |
| 286 | + if sys.version_info >= (3, 11): |
286 | 287 | exc.add_note( |
287 | 288 | "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." |
289 | 291 | ) |
290 | 292 | raise exc |
291 | 293 |
|
|
0 commit comments