Often we want to restrict the set of values on a field to a subset of those allowed by the type, and often the best place to do this is the data model definition itself. For example:
class Car(Struct):
model = String
max_speed = Integer().constrain(GreaterThan(10))
serial = Required(String().constrain(Match(r'^[0-9]{7}-[0-9A-F]{3}$')))
goal:
serializability: just as the pystachio schema can currently be shipped with the data, constraints should be shippable as well
non-goal:
arbitrary code: while it's tempting to just add a callback field, doing so would impair portability
Usage example:
car = Car(max_speed='{{ speed }}').bind(speed=5)
car.interpolate() # should return a failure code.
Often we want to restrict the set of values on a field to a subset of those allowed by the type, and often the best place to do this is the data model definition itself. For example:
goal: serializability: just as the pystachio schema can currently be shipped with the data, constraints should be shippable as well
non-goal: arbitrary code: while it's tempting to just add a callback field, doing so would impair portability
Usage example:
For inspiration see postgresql CHECK constraints.