Attributes with superpowers
Project description
reacttrs
Reactive attributes, initially extracted out from Textual, now a fork of Declare.
from reacttrs import Int, Str
class Foo:
name = Str("Paul")
age = Int(34)
birth = Int(1990)
@name.watch
def _watch_name(self, old: str, new: str):
print(f"{old=}, {new=}")
@age.validate
def _validate_age(self, value: int) -> int:
return 2024 - self.birth
foo = Foo()
foo.name = "John" # old='Paul', new='John'
foo.name = "Steve" # old='John', new='Steve'
print(foo.age) # 34
foo.birth = 1991
foo.age = 34
print(foo.age) # 33
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
reacttrs-0.2.1.tar.gz
(3.5 kB
view details)
Built Distribution
File details
Details for the file reacttrs-0.2.1.tar.gz
.
File metadata
- Download URL: reacttrs-0.2.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a2cbf7a209deb0be056cc30e7c7c5f1ff5a744cba18c427d5418cc32bb1e53c |
|
MD5 | 526c6cf1762a19308b6f11157d628c0f |
|
BLAKE2b-256 | 909033daccaa6587d18e60ccc48a70d3c36e9e2b48db2606f7829b6c687b31fa |
Provenance
File details
Details for the file reacttrs-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: reacttrs-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1425357d8d7b0d8bc89fc1dce2544410296b605429571e11b682492a3060caed |
|
MD5 | ab33dc22d89e5e693993fb2e832b28c6 |
|
BLAKE2b-256 | 450b888bee634da04d8fd8a7d177d48bca3888388145b8445810550e77de8b34 |