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.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.2.tar.gz
.
File metadata
- Download URL: multiton-0.2.2.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 | 89b5d3aaa39c5d5cfd434d82d4c4618cb44399dd579f02274153a063baf316de |
|
MD5 | 962d511bdcda93dbbd8e4a8b22c4d56e |
|
BLAKE2b-256 | 0b0e8e4d8ccdb7194dc48009272501befcedfc9badff3609ac5d0c4a984d6c43 |
File details
Details for the file multiton-0.2.2-py2.py3-none-any.whl
.
File metadata
- Download URL: multiton-0.2.2-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 | 28c6fc881c5e2a91c0a9d7b4872ee70d2c36ac6f87dc68ea7222648cde07a350 |
|
MD5 | 07ac235d6c82fe9595fe525f29828a2d |
|
BLAKE2b-256 | ea3bb2fd207242a14523e0702ffa34dda0d589f6de69ba57482daa10b4034d26 |