mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 14:34:23 +01:00
* Pi's message. * Fix most everything. * Blacked * Add Typing, Docstrings everywhere, organize the code a bit. * Black * fix import * Update message, dedupe. * Increase backoff time. * bump up retries
25 lines
632 B
Python
25 lines
632 B
Python
"""The singleton metaclass for ensuring only one instance of a class."""
|
|
import abc
|
|
|
|
|
|
class Singleton(abc.ABCMeta, type):
|
|
"""
|
|
Singleton metaclass for ensuring only one instance of a class.
|
|
"""
|
|
|
|
_instances = {}
|
|
|
|
def __call__(cls, *args, **kwargs):
|
|
"""Call method for the singleton metaclass."""
|
|
if cls not in cls._instances:
|
|
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
|
return cls._instances[cls]
|
|
|
|
|
|
class AbstractSingleton(abc.ABC, metaclass=Singleton):
|
|
"""
|
|
Abstract singleton class for ensuring only one instance of a class.
|
|
"""
|
|
|
|
pass
|