A Multiton metaclass for preventing duplicate instances based on init values.
Project description
Multiton
A Multiton metaclass for preventing duplicate instances based on init values.
Free software: MIT license
Documentation: https://multiton.readthedocs.io.
Features
Instanciate a class again and get the first instance with the same value back.
Define which values count
Supply callables to get the needed values from the argument.
Quickstart
from multiton import MultitonMetaFactory
class TestMultiton(metaclass=MultitonMetaFactory(0, (1, lambda x: x[1]), kw_b=None) ):
def __init__(self, a, b, kw_a=None, kw_b=None) -> None:
self.a = a
self.b = b
self.kw_a = kw_a
self.kw_b = kw_b
instance_a = TestMultiton(42, [1, 15, 42], kw_a="this is the first instance", kw_b=15)
instance_b = TestMultiton(42, [5, 15, 801], kw_a="this is the second instance", kw_b=15)
assert instance_a is instance_b
print(instance_b.kw_a)
Credits
This package was created with Cookiecutter and the udreyr/cookiecutter-pypackage project template.
History
0.2.3 (2020-08-13)
Dropped Python 3.5 Support
0.2.2 (2020-08-13)
Fixed README.rst
0.2.1 (2020-08-13)
Refactored multition to use multiple arguments and keyword arguments
0.1.1 (2020-08-13)
Fixed README.md
0.1.0 (2020-08-13)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file multiton-0.2.3.tar.gz
.
File metadata
- Download URL: multiton-0.2.3.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d333d1187ad9dae71a2b571ed1472c734989d4e7d6b32de10126b585e49bff7 |
|
MD5 | 144f54b11098524d671d0a0eff58b597 |
|
BLAKE2b-256 | 3976dd6dc8d6e9f4d34c2e0bc7181347201c675c741bf8d7e0f53745e91aa1dd |
File details
Details for the file multiton-0.2.3-py2.py3-none-any.whl
.
File metadata
- Download URL: multiton-0.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c178eae4a6898da580c3ad6daec13e9d7cd7028141e243e18554e44b80a44423 |
|
MD5 | 5b6c4dcd9396d487d31d443ded133dcf |
|
BLAKE2b-256 | 8c480f920891065fa2c3611f20a0433b456ac90f9bf4373f716582ebf0716013 |