Lazy evaluation of dataclass fields
Project description
znfields
Provide a getter
and setter
for dataclasses.fields
to allow e.g. for lazy
evaluation or field content validation.
pip install znfields
Example
The znfields.field
supports all arguments from dataclasses.field
with the
additional getter
argument.
import dataclasses
import znfields
def getter(self, name) -> str:
return f"{name}:{self.__dict__[name]}"
def setter(self, name, value) -> None:
if not isinstance(value, float):
raise ValueError(f"Value {value} is not a float")
self.__dict__[name] = value
@dataclasses.dataclass
class MyModel(znfields.Base):
parameter: float = znfields.field(getter=getter, setter=setter)
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
znfields-0.1.2.tar.gz
(7.0 kB
view details)
Built Distribution
File details
Details for the file znfields-0.1.2.tar.gz
.
File metadata
- Download URL: znfields-0.1.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d9e1894f1a766dd5675db1b1b05cfc6b5c9d78da84a5b01d0baffd5ca49a065 |
|
MD5 | a83a444ccd933cc462316df2ea5c10bf |
|
BLAKE2b-256 | 2c3d4332bc037cf7bf3b5fd2a8e48f5c79d14c8d33b69af3d100a5a0e1e6ca3a |
File details
Details for the file znfields-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: znfields-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 621c4746276a55637bb251494251e09671f4f4e74fbdaad7158d8a225e0d94e8 |
|
MD5 | f98ad77d4b609db8a64a18c6c604e508 |
|
BLAKE2b-256 | b37efaa726144e92f8473157b402d5adec74daf9279605774d6e5b7cf881e676 |