Skip to content

hololinked.core.meta.Propertized

Bases: Parameterized

Base class providing additional functionality related to properties, like setting up a registry, allowing values to be set at __init__() etc. It is not meant to be subclassed directly by the end-user.

UML Diagram

Source code in hololinked/hololinked/core/meta.py
class Propertized(Parameterized):
    """
    Base class providing additional functionality related to properties,
    like setting up a registry, allowing values to be set at `__init__()` etc.
    It is not meant to be subclassed directly by the end-user.

    [UML Diagram](https://docs.hololinked.dev/UML/PDF/Thing.pdf)
    """

    # There is a word called Property+ize in english dictionary
    # https://en.wiktionary.org/wiki/propertization

    id: str

    # creating name without underscore causes clash with the metaclass method
    # with same name
    def create_param_container(self, **params):
        self._properties_registry = PropertiesRegistry(self.__class__, None, self)
        self._properties_registry._setup_parameters(**params)
        self._param_container = self._properties_registry  # backwards compatibility with param

    @property
    def properties(self) -> PropertiesRegistry:
        """container for the property descriptors of the object."""
        return self._properties_registry

    # we need to specification define it as an action to for the possibility of getting an
    # Affordance object associated with it i.e _get_properties.to_affordance() function needs to work.
    # TODO - fix this anomaly
    @action()
    def _get_properties(self, **kwargs) -> dict[str, Any]:
        """ """
        return self.properties.get(**kwargs)

    @action()
    def _set_properties(self, **values: dict[str, Any]) -> None:
        """
        set properties whose name is specified by keys of a dictionary

        Parameters
        ----------
        values: Dict[str, Any]
            dictionary of property names and its values
        """
        return self.properties.set(**values)  # returns None

    @action()
    def _get_properties_in_db(self) -> dict[str, JSONSerializable]:
        """
        get all properties in the database

        Returns
        -------
        Dict[str, JSONSerializable]
            dictionary of property names and their values
        """
        return self.properties.get_from_DB()

    @action()
    def _add_property(self, name: str, prop: JSON) -> None:
        """
        add a property to the object

        Parameters
        ----------
        name: str
            name of the property
        prop: Property
            property object
        """
        raise NotImplementedError("this method will be implemented properly in a future release")
        prop = Property(**prop)
        self.properties.add(name, prop)
        self._prepare_resources()

Attributes

properties property

properties: PropertiesRegistry

container for the property descriptors of the object.