Skip to content

Validation

coola.validation

Contain functions to validate function/method arguments.

coola.validation.validate_ge

validate_ge(
    value: Any, low: Any, *, name: str = "value"
) -> None

Validate that value is greater than or equal to low.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
low Any

The lower bound, inclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is lower than low.

Example
>>> from coola.validation import validate_ge
>>> validate_ge(1, 0)

coola.validation.validate_gt

validate_gt(
    value: Any, low: Any, *, name: str = "value"
) -> None

Validate that value is strictly greater than low.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
low Any

The lower bound, exclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is lower than or equal to low.

Example
>>> from coola.validation import validate_gt
>>> validate_gt(1, 0)

coola.validation.validate_in

validate_in(
    value: Any, valid: Container, *, name: str = "value"
) -> None

Validate that value belongs to valid.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
valid Container

The container of valid values.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is not in valid.

Example
>>> from coola.validation import validate_in
>>> validate_in("a", ("a", "b", "c"))

coola.validation.validate_isinstance

validate_isinstance(
    value: Any,
    cls: type | tuple[type, ...],
    *,
    name: str = "value",
) -> None

Validate that value is an instance of cls.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
cls type | tuple[type, ...]

The type or tuple of types that value must be an instance of.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
TypeError

If value is not an instance of cls.

Example
>>> from coola.validation import validate_isinstance
>>> validate_isinstance(1, int)

coola.validation.validate_le

validate_le(
    value: Any, high: Any, *, name: str = "value"
) -> None

Validate that value is less than or equal to high.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
high Any

The upper bound, inclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is greater than high.

Example
>>> from coola.validation import validate_le
>>> validate_le(0, 1)

coola.validation.validate_lt

validate_lt(
    value: Any, high: Any, *, name: str = "value"
) -> None

Validate that value is strictly less than high.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
high Any

The upper bound, exclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is greater than or equal to high.

Example
>>> from coola.validation import validate_lt
>>> validate_lt(0, 1)

coola.validation.validate_negative

validate_negative(
    value: Any, *, name: str = "value"
) -> None

Validate that value is strictly negative.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is not negative.

Example
>>> from coola.validation import validate_negative
>>> validate_negative(-1)

coola.validation.validate_non_negative

validate_non_negative(
    value: Any, *, name: str = "value"
) -> None

Validate that value is not negative.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is negative.

Example
>>> from coola.validation import validate_non_negative
>>> validate_non_negative(1)

coola.validation.validate_non_positive

validate_non_positive(
    value: Any, *, name: str = "value"
) -> None

Validate that value is not positive.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is positive.

Example
>>> from coola.validation import validate_non_positive
>>> validate_non_positive(-1)

coola.validation.validate_not_empty

validate_not_empty(
    value: Sized, *, name: str = "value"
) -> None

Validate that value is not empty.

Parameters:

Name Type Description Default
value Sized

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is empty.

Example
>>> from coola.validation import validate_not_empty
>>> validate_not_empty([1, 2, 3])

coola.validation.validate_positive

validate_positive(
    value: Any, *, name: str = "value"
) -> None

Validate that value is strictly positive.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is not positive.

Example
>>> from coola.validation import validate_positive
>>> validate_positive(1)

coola.validation.comparison

Contain functions to validate comparisons.

coola.validation.comparison.validate_ge

validate_ge(
    value: Any, low: Any, *, name: str = "value"
) -> None

Validate that value is greater than or equal to low.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
low Any

The lower bound, inclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is lower than low.

Example
>>> from coola.validation import validate_ge
>>> validate_ge(1, 0)

coola.validation.comparison.validate_gt

validate_gt(
    value: Any, low: Any, *, name: str = "value"
) -> None

Validate that value is strictly greater than low.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
low Any

The lower bound, exclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is lower than or equal to low.

Example
>>> from coola.validation import validate_gt
>>> validate_gt(1, 0)

coola.validation.comparison.validate_le

validate_le(
    value: Any, high: Any, *, name: str = "value"
) -> None

Validate that value is less than or equal to high.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
high Any

The upper bound, inclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is greater than high.

Example
>>> from coola.validation import validate_le
>>> validate_le(0, 1)

coola.validation.comparison.validate_lt

validate_lt(
    value: Any, high: Any, *, name: str = "value"
) -> None

Validate that value is strictly less than high.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
high Any

The upper bound, exclusive.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is greater than or equal to high.

Example
>>> from coola.validation import validate_lt
>>> validate_lt(0, 1)

coola.validation.comparison.validate_negative

validate_negative(
    value: Any, *, name: str = "value"
) -> None

Validate that value is strictly negative.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is not negative.

Example
>>> from coola.validation import validate_negative
>>> validate_negative(-1)

coola.validation.comparison.validate_non_negative

validate_non_negative(
    value: Any, *, name: str = "value"
) -> None

Validate that value is not negative.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is negative.

Example
>>> from coola.validation import validate_non_negative
>>> validate_non_negative(1)

coola.validation.comparison.validate_non_positive

validate_non_positive(
    value: Any, *, name: str = "value"
) -> None

Validate that value is not positive.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is positive.

Example
>>> from coola.validation import validate_non_positive
>>> validate_non_positive(-1)

coola.validation.comparison.validate_positive

validate_positive(
    value: Any, *, name: str = "value"
) -> None

Validate that value is strictly positive.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is not positive.

Example
>>> from coola.validation import validate_positive
>>> validate_positive(1)

coola.validation.container

Contain functions to validate containers.

coola.validation.container.validate_in

validate_in(
    value: Any, valid: Container, *, name: str = "value"
) -> None

Validate that value belongs to valid.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
valid Container

The container of valid values.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is not in valid.

Example
>>> from coola.validation import validate_in
>>> validate_in("a", ("a", "b", "c"))

coola.validation.container.validate_not_empty

validate_not_empty(
    value: Sized, *, name: str = "value"
) -> None

Validate that value is not empty.

Parameters:

Name Type Description Default
value Sized

The value to validate.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
ValueError

If value is empty.

Example
>>> from coola.validation import validate_not_empty
>>> validate_not_empty([1, 2, 3])

coola.validation.type

Contain functions to validate types.

coola.validation.type.validate_isinstance

validate_isinstance(
    value: Any,
    cls: type | tuple[type, ...],
    *,
    name: str = "value",
) -> None

Validate that value is an instance of cls.

Parameters:

Name Type Description Default
value Any

The value to validate.

required
cls type | tuple[type, ...]

The type or tuple of types that value must be an instance of.

required
name str

The name of the value, used in the error message.

'value'

Raises:

Type Description
TypeError

If value is not an instance of cls.

Example
>>> from coola.validation import validate_isinstance
>>> validate_isinstance(1, int)