create perfect singletons meta
Project description
singleton_meta
Features
- perfect singleton (maybe thread safe!)
- collect all instances
License
See the LICENSE file for license rights and limitations (MIT).
Release history
See the HISTORY.md file for release history.
Installation
pip install singleton-meta
Import
from singleton_meta import *
GUIDE
See tests and source for other examples.
1. Use simple nesting (common)
from singleton_meta import *
class MySingleton(SingletonWMetaCall):
pass
class MySingleton2(SingletonWMetaCall):
pass
2. access to created instances
from singleton_meta import *
class Victim1(SingletonWMetaCall):
attr = 1
class Victim2(SingletonWMetaCall):
attr = 2
assert SingletonWMetaCall._SINGLETONS == []
Victim1()
assert SingletonWMetaCall._SINGLETONS == [Victim1(), ]
Victim2()
assert SingletonWMetaCall._SINGLETONS == [Victim1(), Victim2(), ]
3. Use meta
from singleton_meta import *
class MySingleton(metaclass=SingletonMetaClass):
pass
4. NOTICE: all your Singletons must be only last classes!
don't use nesting from any Your Singletons!
from singleton_meta import *
class MySingleton(SingletonWMetaCall): # OK
pass
class MySingleton2(MySingleton): # WRONG
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
singleton_meta-0.0.5.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for singleton_meta-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 732c9cc2a287f620d19f9ca3a94e534de3d4d4d0e7bec97165bb5b4fce06a1bf |
|
MD5 | 7e92126835cc11652df3434cba15958e |
|
BLAKE2b-256 | fd5ee18ade1b3db501c5bd3933e68a0e889f835275826be5735a7445aa79e88b |