No project description provided
Project description
indexed_meta
Python metaclass with support for per-class specialization via an index method.
Adds a __param__
field to classes programmatically so that you can store a
static field on them without having to define a new class and without having to
use a new name.
from indexed_meta import IndexedMetaclass # Base type but either will work fine
from indexed_meta import IndexedClass # Convenience type. Fixes repr(), str()
class Vec(IndexedClass):
def show(self):
# This is the value-add for this library. Use __param__ as you see fit.
# It is different per specialized class but the exact same when param is
# the same: Vec[1] == Vec[1]; Vec[1] != Vec[2]
print(self.__param__)
v1 = Vec[3]()
v1.show() # Prints `3`
Vec[1], Vec[2], Vec[3], Vec[1, 2, 3], Vec[frozenset([1, 2, 3])]
# It's possible to override the default __param__ of None by inheriting from a
# specialized class:
class Vec(metaclass=IndexedMetaclass):
...
class Vec4(Vec[4]):
...
assert Vec4.__param__ == 4 # Normally it would be `None`
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
indexed_meta-0.0.3.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for indexed_meta-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb9d55c1bcd1cd909720ee10fd4abba2f36307c9c8a0751c863e861411af708 |
|
MD5 | 32e7e99d77546b236a2a7273ae3da626 |
|
BLAKE2b-256 | 3f5d297f3e9507fc422dfc70630cded8ae19a30c3efe34f6e291b94ac0829c0e |