Skip to content

hololinked.core.meta.ThingMeta

Bases: ParameterizedMetaclass

Metaclass for Thing, implements a __post_init__() call and instantiation of a registry for properties', actions' and events' descriptor objects.

Accessing properties, actions and events at the class level returns the descriptor object through the DescriptorRegistry implementation. Accessing properties, actions and events at instance level return their values (for example - the value of Property foo being 5). __post_init__() is run after the user's __init__() method, properties that can be loaded from a database are loaded and written at this time. Overload __post_init__() in subclasses to add additional functionality.

UML Diagram

Source code in repo/hololinked/hololinked/core/meta.py
class ThingMeta(ParameterizedMetaclass):
    """
    Metaclass for `Thing`, implements a `__post_init__()` call and instantiation of a registry for properties', actions' and events' descriptor objects.

    Accessing properties, actions and events at the class level returns the descriptor object through the `DescriptorRegistry`
    implementation. Accessing properties, actions and events at instance level return their values (for example -
    the value of Property `foo` being `5`).
    `__post_init__()` is run after the user's `__init__()` method, properties that can be
    loaded from a database are loaded and written at this time. Overload `__post_init__()` in subclasses
    to add additional functionality.

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

    def __init__(mcs, name, bases, dict_):
        super().__init__(name, bases, dict_)
        mcs._create_actions_registry()
        mcs._create_events_registry()

    def __call__(mcls, *args, **kwargs):
        """
        Instantiate the class and run `__post_init__()` on the new instance.

        Returns
        -------
        instance: Thing
            the newly created instance, after `__post_init__()` has run
        """
        instance = super().__call__(*args, **kwargs)
        instance.__post_init__()
        return instance

    def _create_param_container(cls, cls_members: dict) -> None:  # ty: ignore[invalid-method-override]
        """
        Creates `PropertiesRegistry` instead of `param`'s own `Parameters` as the default container for descriptors.

        All properties have definitions copied from `param`.
        """
        cls._param_container = PropertiesRegistry(cls, cls_members)

    def _create_actions_registry(cls) -> None:
        """
        Creates `Actions` instead of `param`'s own `Parameters` as the default container for descriptors.

        All actions have definitions copied from `param`.
        """
        cls._actions_registry = ActionsRegistry(cls)

    def _create_events_registry(cls) -> None:
        """
        Creates `Events` instead of `param`'s own `Parameters` as the default container for descriptors.

        All events have definitions copied from `param`.
        """
        cls._events_registry = EventsRegistry(cls)

    @property
    def properties(cls) -> "PropertiesRegistry":
        """
        Container object for Property descriptors.

        Returns `PropertiesRegistry` instance instead of `param`'s own `Parameters` instance.
        """
        return cls._param_container  # ty: ignore[invalid-return-type]

    @property
    def actions(cls) -> "ActionsRegistry":
        """Container object for Action descriptors."""
        return cls._actions_registry

    @property
    def events(cls) -> "EventsRegistry":
        """Container object for Event descriptors."""
        return cls._events_registry

    use_json_file: bool
    """Set to `True` to activate JSON file based configuration management."""
    use_default_db: bool
    """Set to `True` to activate default SQLite based configuration management."""
    use_mongo_db: bool
    """Set to `True` to activate MongoDB based configuration management."""

Attributes

actions property

actions: ActionsRegistry

Container object for Action descriptors.

events property

events: EventsRegistry

Container object for Event descriptors.

properties property

properties: PropertiesRegistry

Container object for Property descriptors.

Returns PropertiesRegistry instance instead of param's own Parameters instance.

use_default_db instance-attribute

use_default_db: bool

Set to True to activate default SQLite based configuration management.

use_json_file instance-attribute

use_json_file: bool

Set to True to activate JSON file based configuration management.

use_mongo_db instance-attribute

use_mongo_db: bool

Set to True to activate MongoDB based configuration management.

Functions

__call__

__call__(mcls, *args, **kwargs)

Instantiate the class and run __post_init__() on the new instance.

Returns:

Name Type Description
instance Thing

the newly created instance, after __post_init__() has run

Source code in repo/hololinked/hololinked/core/meta.py
def __call__(mcls, *args, **kwargs):
    """
    Instantiate the class and run `__post_init__()` on the new instance.

    Returns
    -------
    instance: Thing
        the newly created instance, after `__post_init__()` has run
    """
    instance = super().__call__(*args, **kwargs)
    instance.__post_init__()
    return instance