blob: 55be70eb47faf2ea55d80315fdbb364bf0e0708c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
from typing import Dict, Any
class _Singleton(type):
""" A metaclass that creates a Singleton base class when called. """
_instances: Dict[Any, Any] = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super().__call__(*args, **kwargs)
return cls._instances[cls]
class Singleton(_Singleton('SingletonMeta', (object,), {})): # type: ignore
pass
|