pip install singletonifyfrom singletonify import singleton
@singleton(a=3)
class YourClass:
def __init__(self, a): ...
assert YourClass() is YourClass()There are many singleton libraries on pypi, but their all has problem:
- singleton - cannot use
issubclass()or__mro__or ... - singleton-decorator - cannot use
isinstance(). - singleton_factory - wtf, why do people use
dict()[hash(obj)] = obj? - singletonmetaclasss - a little like this, but not a decorator.
- singleton3 - haha
- pysingleton - ABANDONED.