This commit is contained in:
2023-05-31 19:31:00 +08:00
commit d16c25726a
10 changed files with 745 additions and 0 deletions

View File

@ -0,0 +1,12 @@
from typing import TypeVar, Generic
T = TypeVar("T")
class Singleton(type, Generic[T]):
_instance = None
def __call__(cls, *args, **kwargs) -> T:
if cls._instance is None:
cls._instance = super().__call__(*args, **kwargs)
return cls._instance