cottax.core.frozen.violation module¶
Violations of the checks: supporting diagnostics as well as raising.
- class Violation[source]¶
Bases:
FrozenViolation: can raise or used to debug.
- error: AbstractClassVar[type[Exception]]¶
Exception raised for this violation
- template: AbstractClassVar[str]¶
e.g. ‘output {place!r} is owned by both {other!r} and {node!r}’
- Type:
Wording
- property where: dict[str, object]¶
places, node names, or tuples of either.
- Type:
The fields, by role
- property message: str¶
- property raised: Exception¶
The exception a caller expects for this violation, carrying it as violation, so a refusal caught is still data.
- first(violations: Iterable[Violation])[source]¶
Raise the first violation, if any – the boundary between rules-as-data and the exceptions a constructor owes its caller.
- Return type:
None
- checked[F: Callable](*checks: Callable[..., Iterable[Violation]])[source]¶
A function declaring its checks as a class does: each is called with the function’s arguments as it receives them, and the first violation is raised before the body runs.
- Return type:
Callable[[F],F]
- violations(cls: type[Frozen] | Callable, *args, skip: Collection[Callable] = (), **kwargs)[source]¶
Every case cls(*args, **kwargs) breaks, as data: built with the checks skipped, then each rule down the hierarchy asked and everything it yields collected (wherever possible; some checks cannot be run on totally invalid data (e.g. a nesting check for a nesting not in the graph)). A checked function’s checks are asked of its arguments, and its body never runs.
- Return type:
Iterator[Violation]