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.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
Hashes for multiton-0.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26f21c6db098411870edb9c6eec578517660763b734d8adf3923aab8b4cc9804 |
|
MD5 | 5946c2c5e876f973e5583acea3f1e318 |
|
BLAKE2b-256 | 7f00f5d9439664ae364dddf85a65ed04b39cf57b1cd3f5b0004c80e4d57fdf1e |