Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-abstract Savable by making it a protocol #298

Draft
wants to merge 29 commits into
base: dev
Choose a base branch
from

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Dec 12, 2024

The outcome of this refactoring is that the Savable become a protocol which provide the contract for how things needed to be saved should implemented.

@runtime_checkable
class Savable(Protocol):
    @classmethod
    def recreate_from(cls, saved_state: SAVED_STATE_TYPE, load_context: LoadSaveContext | None = None) -> 'Savable':
        """
        Recreate a :class:`Savable` from a saved state using an optional load context.

        :param saved_state: The saved state
        :param load_context: An optional load context

        :return: The recreated instance

        """
        ...

    def save(self, save_context: LoadSaveContext | None = None) -> SAVED_STATE_TYPE: ...

Compare to the original implementation where save calls save_instance_state calls each other recursively until all savable things is saved, the new implementation force the save method independent and have symmetry behavior of recreate_from.

unkcpz added 29 commits December 2, 2024 09:35
create_state refact

Hashable initialized + parameters passed to Hashable

Fix pre-commit errors
For the auto_persist attributes, the fn auto_save will take care of save
the state
- stepper de-abstract
- remove ContextMixin
- Stepper all using recreate_from
- remove persist_config flag of savable
@unkcpz unkcpz marked this pull request as draft December 12, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant