singletonify
install
pip install singletonify
usage
@singleton(a=3)
class YourClass:
def __init__(self, a): ...
assert YourClass() is YourClass()
why not other
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.