def range_validator(minval=None, maxval=None):
    """Generates a function that validates that a number is within range

    Parameters
    ==========
    minval: numeric, optional:
        Values strictly lesser than `minval` are rejected
    maxval: numeric, optional:
        Values strictly greater than `maxval` are rejected

    Returns
    =======
    A function that returns values if are in the range and raises
    ValidationError is the values are outside the range

    """
    def checker_func(value):
        if minval is not None and value < minval:
            msg = "must be >= {}".format(minval)
            raise ValidationError(msg)
        if maxval is not None and value > maxval:
            msg = "must be <= {}".format(maxval)
            raise ValidationError(msg)
        return value

    return checker_func
Generates a function that validates that a number is within range

    Parameters
    ==========
    minval: numeric, optional:
        Values strictly lesser than `minval` are rejected
    maxval: numeric, optional:
        Values strictly greater than `maxval` are rejected

    Returns
    =======
    A function that returns values if are in the range and raises
    ValidationError is the values are outside the range