UNKNOWN
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mutexinit-0.0.tar.gz
(1.3 kB
view details)
File details
Details for the file mutexinit-0.0.tar.gz
.
File metadata
- Download URL: mutexinit-0.0.tar.gz
- Upload date:
- Size: 1.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b39d84caae2f31355b75833d60cef8c621f459b8a7e021a3ec393c37aa4167fd |
|
MD5 | d79699c469bd8595ec39641587de5b94 |
|
BLAKE2b-256 | 29152fda4f4290f28efc3fc13909edb4dc07a5d82f228432bc197fd7948b5b8d |