Computed¶
didactic.api.computed ¶
computed(
fn: Callable[..., FieldValue] | None = None,
*,
materialise: bool = False,
) -> (
property
| Callable[[Callable[..., FieldValue]], property]
)
Mark a method as a computed field on a Model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., FieldValue] | None
|
The method to mark. Supplied positionally when the decorator is
used without arguments ( |
None
|
materialise
|
bool
|
Recorded on the underlying property's marker for downstream tooling (theory codegen, axiom emission). At the Python level this flag has no effect: the value is always recomputed on access, never stored. |
False
|
Returns:
| Type | Description |
|---|---|
property or Callable
|
Either a |
Notes
The wrapped method should take self and return a value of any
didactic-supported type. Computed fields participate in
model_dump but never in storage.
Examples:
>>> import didactic.api as dx
>>> class Person(dx.Model):
... first_name: str
... last_name: str
...
... @dx.computed
... def full_name(self) -> str:
... return f"{self.first_name} {self.last_name}"
>>> p = Person(first_name="Ada", last_name="Lovelace")
>>> p.full_name
'Ada Lovelace'
>>> p.model_dump()["full_name"]
'Ada Lovelace'