hydration icon indicating copy to clipboard operation
hydration copied to clipboard

Change a validator after assigned a value

Open avivatedgi opened this issue 5 years ago • 0 comments

There is a feature to change the validator (with a property setter). After changing the validator to a new one, there is a need to revalidate the value that assigned to the field. For example:

def test_validation_changes():
    class Rondo(h.Struct):
        paz = h.Int32(5, validator=h.RangeValidator(range(0, 6)))

    rondo = Rondo()
    rondo.paz = 3
    # This line should throw an exception because the value is 5
    # and the value that is allowed now is a range between 6 to 10
    rondo.paz.validator = h.RangeValidator(range(6, 10))

avivatedgi avatar Feb 11 '20 17:02 avivatedgi