create perfect singletons
Project description
singleton_meta (v0.1.3)
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.3.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file singleton_meta-0.1.3.tar.gz
.
File metadata
- Download URL: singleton_meta-0.1.3.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68eb788b9c3a43b39a68e5f9fdbf0ef0466e31c45c6c6a118bfea84780eee413 |
|
MD5 | 65ce726f7e9703f35eb1e1c18b074312 |
|
BLAKE2b-256 | 765f7be94390a563cdbf2ae62fb867a013663a5c9ed8aa60e786387f1438485d |
File details
Details for the file singleton_meta-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: singleton_meta-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.7 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 | 5948702b1d9cd6c3cb0c6dce83f620f4ff658532bfec47d2bb464f50a0daba2b |
|
MD5 | 521c4d2b0a9ac8ed55e41793502fe38c |
|
BLAKE2b-256 | e430e2015d2c55cbe141e268e0fb20b1498f236d0acb8b88b5de9f972f9f2eda |