from typing import Optional


def _min_max(
    min: Optional[int] = None,  # noqa: WPS125
    max: Optional[int] = None,  # noqa: WPS125
):
    """Validator to check that value is in bounds."""
    def factory(instance, attribute, field_value):
        min_contract = min is not None and field_value < min
        max_contract = max is not None and field_value > max
        if min_contract or max_contract:
            raise ValueError('Option {0} is out of bounds: {1}'.format(
                attribute.name,
                field_value,
            ))
    return factory