Validation Classes¶
ValidationResult¶
Result from .validate() on a validating combinator.
Methods:
raise_if_invalid(exc_type: type[Exception]) -> None-- Raise an exception if validation failed
Example:
result = can_trade.validate(user)
if not result.ok:
print(result.errors)
# ["User Bob must be an admin", "Account must be older than 30 days"]
result.raise_if_invalid(ValueError)
ValidatingCombinator¶
Base class for validating combinators. Supports &, |, and ~ operators.
Methods:
validate(ctx: T) -> ValidationResult[T]-- Run validation and collect all errors
ValidatingPredicate¶
Predicate with an error message. Created by @vrule and @vrule_args.
The error can be a format string (using {ctx} and parameter names) or a callable (ctx) -> str.
Example:
AsyncValidatingCombinator¶
Async base class for validating combinators. Supports &, |, and ~ operators.
Methods:
async validate(ctx: T) -> ValidationResult[T]-- Run async validation
AsyncValidatingPredicate¶
Async predicate with an error message. Created by @async_vrule and @async_vrule_args.
Example: