Skip to main content

mutexinit

This package provides a metaclass and a decorator to enable mutually exclusive constructors for Python classes.

All you need to do is just make a class with the MutexInitMeta metaclass and declare each mutually exclusive constructor as a instance method, and also decorate it with @subinit decorator.

Here is a simple example:

from mutexinit import MutexInitMeta, subinit

class MyClass(object):
    __metaclass__ = MutexInitMeta

    @subinit
    def foo(self, bar, baz):
        print('Running "foo" constructor')

    @subinit
    def bar(self, foo, baz):
        print('Running "bar" constructor')

This is all to make a class to have mutually exclusive constructors. After defining the class, go ahead, and initialise it:

>>> my_instance1 = MyClass(bar=1, baz=2)
Running "foo" constructor
>>> my_instance2 = MyClass(foo=9, baz=8)
Running "bar" constructor
>>> my_instance2 = MyClass(foo=None, baz=8)
AttributeError: Mutex init arguments cannot be None

Metadata

Release files for mutexinit 0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mutexinit 0.0
File Size Uploaded Provenance Actions
mutexinit-0.0.tar.gz 1.3 kB Without provenance Details for mutexinit-0.0.tar.gz

Release files / mutexinit-0.0.tar.gz

Download URL mutexinit-0.0.tar.gz
Size 1.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b39d84caae2f31355b75833d60cef8c621f459b8a7e021a3ec393c37aa4167fd
BLAKE2b-256 checksum
How to use checksums
29152fda4f4290f28efc3fc13909edb4dc07a5d82f228432bc197fd7948b5b8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for mutexinit 0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page