tgs / bot /utils /singleton.py
AZILS's picture
Upload 119 files
054900e verified
raw
history blame contribute delete
446 Bytes
from __future__ import annotations
from typing import Any, ClassVar
SingletonMetaType = type["SingletonMeta"]
class SingletonMeta(type):
_instances: ClassVar[dict[type, SingletonMetaType]] = {}
def __call__(cls, *args: Any, **kwargs: Any) -> SingletonMetaType:
if cls not in cls._instances:
instance = super().__call__(*args, **kwargs)
cls._instances[cls] = instance
return cls._instances[cls]