RestrictFunction

class ipkiss3.all.RestrictFunction(validator_function, **kwargs)

restricts the value to those that return ‘True’ when passed to a given function

Parameters
validator_function: callable

A function or callable that returns a bool to validate the passed value.

Examples

from ipkiss.all import *

def is_even(val):
    return (val % 2) == 0

class Example(StrongPropertyInitializer):

    num_prop = DefinitionProperty(restriction=RestrictFunction(is_even))

example1 = Example(num_prop=2) # this is ok
example2 = Example(num_prop=1) # this will fail
validator_function
validate(value, obj=None)