From 1598f9010d581b36e767bde3a82f259dec966b2f Mon Sep 17 00:00:00 2001 From: Malik Irain Date: Wed, 3 Sep 2025 17:10:19 +0200 Subject: [PATCH] Rewrite H5Exporter and factory to remove class properties --- src/pymodaq_data/h5modules/exporter.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/pymodaq_data/h5modules/exporter.py b/src/pymodaq_data/h5modules/exporter.py index f053bab1..a22a0fba 100644 --- a/src/pymodaq_data/h5modules/exporter.py +++ b/src/pymodaq_data/h5modules/exporter.py @@ -18,24 +18,14 @@ logger = set_logger(get_module_name(__file__)) -class H5Exporter(metaclass=ABCMeta): - """Base class for an exporter. """ - # This is to define an abstract class attribute - @classmethod - @property - @abstractmethod - def FORMAT_DESCRIPTION(cls): - """str: file format description as a short text. eg: text file""" - raise NotImplementedError - @classmethod - @property - @abstractmethod - def FORMAT_EXTENSION(cls): - """str: File format extension. eg: txt""" - raise NotImplementedError +class H5Exporter(metaclass=ABCMeta): + """Base class for an exporter. """ + FORMAT_EXTENSION: str = NotImplemented + FORMAT_DESCRIPTION: str = NotImplemented + def __init__(self): """Abstract Exporter Constructor""" pass @@ -63,6 +53,11 @@ def register_exporter(cls) -> Callable: """ def inner_wrapper(wrapped_class) -> Callable: + if wrapped_class.FORMAT_EXTENSION is NotImplemented or \ + wrapped_class.FORMAT_DESCRIPTION is NotImplemented: + raise NotImplementedError(f'{wrapped_class} does not properly provide a valid value for ' + f'`FORMAT_EXTENSION` ({wrapped_class.FORMAT_EXTENSION}) or for ' + f'`FORMAT_DESCRIPTION` ({wrapped_class.FORMAT_DESCRIPTION})') extension = wrapped_class.FORMAT_EXTENSION format_desc = wrapped_class.FORMAT_DESCRIPTION