Skip to content

Add BaseSteppable and BaseResettable classes #80

@github-actions

Description

@github-actions

They would inherit from `BaseObject` and have `step` and `reset` methods, respectively. The goal is to standardize

the interface as much as possible (for clarity and ease of use).

# TODO: Add `BaseSteppable` and `BaseResettable` classes
# They would inherit from `BaseObject` and have `step` and `reset` methods, respectively. The goal is to standardize
# the interface as much as possible (for clarity and ease of use).

from abc import abstractmethod

# TODO: Add `BaseSteppable` and `BaseResettable` classes
#   They would inherit from `BaseObject` and have `step` and `reset` methods, respectively. The goal is to standardize
#   the interface as much as possible (for clarity and ease of use).


class BaseObject:
    def __init__(
        self,
        universe: "Universe",
    ):
        self._universe: "Universe" = universe

        self._is_constructed: bool = False
        self._is_post_constructed: bool = False

    def __str__(self):
        return f"{self.__class__.__name__}"

    @property
    def is_constructed(self):
        return self._is_constructed

    @property
    def is_post_constructed(self):
        return self._is_post_constructed

    @property
    def is_fully_constructed(self):
        return self._is_constructed and self._is_post_constructed

    def register_self(self, *args, **kwargs) -> None:
        self._universe.register_object(self, *args, **kwargs)

    @abstractmethod
    def construct(self, *args) -> None:
        assert (
            not self._is_constructed
        ), f"{self} has already been constructed: tried to construct!"

    @abstractmethod
    def post_construct(self, **kwargs) -> None:
        assert (
            not self._is_post_constructed
        ), f"{self} has already been post-constructed: tried to post-construct!"

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions