create perfect singletons
Project description
singleton_meta (v0.1.2)
DESCRIPTION_SHORT
create perfect singletons
DESCRIPTION_LONG
designed for singletons creation
Features
- perfect singleton (maybe thread safe!)
- collect all instances
- check correct instantiating singletons in tree project
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 *
USAGE EXAMPLES
See tests and sourcecode for other examples.
1. example1.py
from singleton_meta import *
class MySingleton(SingletonByCallMeta):
pass
class MySingleton2(SingletonByCallMeta):
pass
class MySingleton(metaclass=SingletonMetaCallClass):
pass
# ===============================
# 2. access to created instances
from singleton_meta import *
class Victim1(SingletonByCallMeta):
attr = 1
class Victim2(SingletonByCallMeta):
attr = 2
assert SingletonByCallMeta._SINGLETONS == []
Victim1()
assert SingletonByCallMeta._SINGLETONS == [Victim1(), ]
assert Victim1._SINGLETONS == [Victim1(), ]
assert Victim1()._SINGLETONS == [Victim1(), ]
Victim2()
assert SingletonByCallMeta._SINGLETONS == [Victim1(), Victim2(), ]
# ===============================
# 3. NOTICE: all your Singletons must be only last classes!
# don't use nesting from any Your Singletons!
from singleton_meta import *
class MySingleton(SingletonByCallMeta): # 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.1.2.tar.gz
(5.2 kB
view details)
Built Distribution
File details
Details for the file singleton_meta-0.1.2.tar.gz
.
File metadata
- Download URL: singleton_meta-0.1.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d8c4726a69632da1c6b1980bb819f4bcb6927d1be35504ca9b02930e014183e |
|
MD5 | 61641f4b47c8b4565b876257181f5f2b |
|
BLAKE2b-256 | 732478ac5051dd50cf940acabc59aeff9676b6761ef6bec4ec3dde9fbc4b9cfd |
File details
Details for the file singleton_meta-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: singleton_meta-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cf6bc9f142bcdc389536ee3664154e929d59009c9c5bca76131949a16114d4b |
|
MD5 | 1ce75e80d679f8c5c8c0363912b25db1 |
|
BLAKE2b-256 | d7e3bec8d2c73f744a06674a81c8d5692e4d6808a8b5f94bb9b646dc8f9b8f56 |