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
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)
| File | Size | Uploaded | |
|---|---|---|---|
| mutexinit-0.0.tar.gz | 1.3 kB | Details |
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 |