def within(min=None, max=None):
    """
    Create a validation function to check whether an argument value is within
    a specified range (inclusive).

    `min` and `max` cannot both be None.
    :param min: A lower bound for the value. Optional.
    :param max: An upper bound for the value. Optional.
    :return: A validation function
    """
    if min is None and max is None:
        raise ValueError("A min or max value must be specified")

    def validate_within(value):
        return (min is None or value >= min) and (max is None or value <= max)

    return validate_within