Everything is connected, maan!
Project description
dprop
Everything is connected, maan!
This tiny package implements the notion of "dependent properties", whose values
are computed based on other properties and cached for re-use, but then smartly
invalidated when a (great-)*(grand)?parent
property's value changes.
Here is a simple example:
from dprop import independent, depends_on
class Class:
a = independent(float) # type info optional
@depends_on(a)
def b(self):
print('computing b')
return 6 * self.a
def __init__(self, a: float):
# independent properties can be set inside and outside the class as usual
self.a = a
inst = Class(7)
assert inst.a == 7
assert inst.b == 42 # prints "computing b"
assert inst.b == 42 # value is re-used! (nothing printed)
# Re-setting an independent property invalidates (does not actually delete,
# though) all "later" properties.
inst.a = 26/6
assert inst.b == 26 # prints "computing b"
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
dprop-0.42.tar.gz
(3.9 kB
view details)
File details
Details for the file dprop-0.42.tar.gz
.
File metadata
- Download URL: dprop-0.42.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 059a1c5a568e6c1d2fa5b3cc9c689da181b84c9c3c44f476b8474dd62585170b |
|
MD5 | 76cda4865d6e63fca881cdd9cc383b6d |
|
BLAKE2b-256 | 54fdc958126dfb9101da067848957000c31926f04277d82efd077a93c268e1ba |