Skip to content

declearn.data_info.register_data_info_field

Decorator to register DataInfoField subclasses.

Source code in declearn/data_info/_base.py
125
126
127
128
129
130
131
132
133
134
135
136
def register_data_info_field(
    cls: Type[DataInfoField],
) -> Type[DataInfoField]:
    """Decorator to register DataInfoField subclasses."""
    if not issubclass(cls, DataInfoField):
        raise TypeError(
            f"Cannot register '{cls}': not a DataInfoField subclass."
        )
    if cls.field in DATA_INFO_FIELDS:
        raise KeyError(f"DataInfoField name '{cls.field}' is already used.")
    DATA_INFO_FIELDS[cls.field] = cls
    return cls