Skip to content

singleton_mixin

SingletonMixin

Source code in griptape/mixins/singleton_mixin.py
class SingletonMixin:
    _instance = None

    def __new__(cls, *args, **kwargs) -> SingletonMixin:
        if not cls._instance:
            cls._instance = super().__new__(cls, *args, **kwargs)  # noqa: UP008
        return cls._instance

__new__(*args, **kwargs)

Source code in griptape/mixins/singleton_mixin.py
def __new__(cls, *args, **kwargs) -> SingletonMixin:
    if not cls._instance:
        cls._instance = super().__new__(cls, *args, **kwargs)  # noqa: UP008
    return cls._instance