Validators¶
didactic.api.validates ¶
validates(
*field_names: str, mode: str = "after"
) -> Callable[
[Callable[..., FieldValue]], Callable[..., FieldValue]
]
Mark a class method as a Python-side validator for one or more fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*field_names
|
str
|
Names of the fields this validator applies to. At least one is required. |
()
|
mode
|
str
|
Either |
'after'
|
Returns:
| Type | Description |
|---|---|
Callable
|
A decorator that tags the wrapped method for the metaclass to register on the field spec. |
Notes
Validators are deliberately not lifted into the Theory; for
cross-language constraints, use __axioms__ or Annotated[T, ...]
metadata instead.
Examples:
didactic.api.ValidationError
dataclass
¶
ValidationError(
entries: tuple[ValidationErrorEntry, ...],
model: type | None = None,
)
Bases: Exception
One or more validation failures, surfaced as a single exception.
didactic collects all failures during construction or mutation and raises them together (no fail-fast). This mirrors Pydantic's behaviour so users who grep "for the list of errors" find one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
tuple[ValidationErrorEntry, ...]
|
The individual failures. |
required |
model
|
type | None
|
The model class that failed validation. |
None
|
See Also
ValidationErrorEntry : the per-issue record.
didactic.api.ValidationErrorEntry
dataclass
¶
ValidationErrorEntry(
loc: tuple[str | int, ...],
type: str,
msg: str,
axiom: str | None = None,
vertex_id: str | None = None,
)
A single validation failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loc
|
tuple[str | int, ...]
|
Path through the schema where the failure was detected, e.g.
|
required |
type
|
str
|
Error category. One of |
required |
msg
|
str
|
Human-readable description. |
required |
axiom
|
str | None
|
The panproto-Expr term that failed, when applicable. |
None
|
vertex_id
|
str | None
|
The schema vertex id where the violation lives, when known. |
None
|