Skip to main content

A Multiton metaclass for preventing duplicate instances based on init values.

Project description

Multiton

pypi travis docs

A Multiton metaclass for preventing duplicate instances based on init values.

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

multiton-0.2.3.tar.gz (13.0 kB view hashes)

Uploaded Source

Built Distribution

multiton-0.2.3-py2.py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page