Skip to content

Singleton

src.utils.properties.Singleton

Bases: type

Maintains a single instance of any child class.

Source code in src\utils\properties.py
163
164
165
166
167
168
169
170
class Singleton(type):
    """Maintains a single instance of any child class."""
    _instances: dict = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]