Skip to main content

validate_as_int

Validates that a given value can be interpreted as an integer and returns the integer representation, or raises a ValueError if the conversion fails.

def validate_as_int(
value: Any,
min_value: int = None,
max_value: int = None
) - > int

Validates that a given value can be interpreted as an integer and falls within an optional inclusive range.

Parameters

NameTypeDescription
valueAnyThe input value to be validated and converted into an integer.
min_valueint = NoneThe minimum allowable value for the integer; validation fails if the value is less than this.
max_valueint = NoneThe maximum allowable value for the integer; validation fails if the value is greater than this.

Returns

TypeDescription
intThe validated integer value if all checks pass.