mastermind.validation.base package

class mastermind.validation.base.base.StateValidator(value: Any)[source]

Bases: Validator[T], ABC

An abstract base class for state validators.

Provides a base implementation for managing the state of a validated value, including validation of modifications.

abstract validate_modifications(new_value: Any) None[source]

Validates the modification of the value.

Parameters:

new_value (Any) – The new value to be validated.

Raises:

ValidationError – If the new value is invalid.

property value: T

Returns the validated value.

Returns:

The validated value.

Return type:

T

class mastermind.validation.base.base.ValidationModel(**kwargs)[source]

Bases: Validator[T], ABC

An abstract base class for validation models.

Provides a base implementation for initializing the validation model with keyword arguments and validating the arguments.

validate_arguments() None[source]

Validates the arguments used to initialize the validation model.

This method must be implemented by subclasses to perform any necessary validation.

class mastermind.validation.base.base.Validator[source]

Bases: ABC, Generic[T]

An abstract base class for all validators.

Defines the validate_value method that must be implemented by subclasses.

abstract validate_value(value: Any) T[source]

Validates the given value and returns the validated value.

Parameters:

value (Any) – The value to be validated.

Returns:

The validated value.

Return type:

T

exception mastermind.validation.base.exceptions.InputConversionError[source]

Bases: ValidationError

Raised when a value cannot be converted to the expected type.

exception mastermind.validation.base.exceptions.InvalidModificationError[source]

Bases: ValidationError

Raised when a modification to a validated value is invalid.

exception mastermind.validation.base.exceptions.MissingParameterError[source]

Bases: ValidationError

Raised when a required parameter is missing.

exception mastermind.validation.base.exceptions.RangeError[source]

Bases: ValidationError

Raised when a value is outside the expected range.

exception mastermind.validation.base.exceptions.TypeValidationError[source]

Bases: ValidationError

Raised when a value does not match the expected type.

exception mastermind.validation.base.exceptions.ValidationError[source]

Bases: Exception

The base class for all validation-related exceptions.

class mastermind.validation.base.numeric.ConstrainedFloat(gt: Number | None = None, lt: Number | None = None, ge: Number | None = None, le: Number | None = None)[source]

Bases: NumberRangeModel[float]

A NumberRangeModel that validates float values within a specified range.

convert(value: str) float[source]

Converts the given string value to a float.

Parameters:

value (str) – The string value to be converted.

Returns:

The converted float value.

Return type:

float

Raises:

InputConversionError – If the value cannot be converted to a float.

class mastermind.validation.base.numeric.ConstrainedInteger(gt: Number | None = None, lt: Number | None = None, ge: Number | None = None, le: Number | None = None)[source]

Bases: NumberRangeModel[int]

A NumberRangeModel that validates integer values within a specified range.

convert(value: str) int[source]

Converts the given string value to an integer.

Parameters:

value (str) – The string value to be converted.

Returns:

The converted integer value.

Return type:

int

Raises:

InputConversionError – If the value cannot be converted to an integer.

class mastermind.validation.base.numeric.NumberRangeModel(gt: Number | None = None, lt: Number | None = None, ge: Number | None = None, le: Number | None = None)[source]

Bases: ValidationModel[T]

A ValidationModel that validates numeric values within a specified range.

gt

The minimum value (exclusive).

Type:

Optional[Number]

lt

The maximum value (exclusive).

Type:

Optional[Number]

ge

The minimum value (inclusive).

Type:

Optional[Number]

le

The maximum value (inclusive).

Type:

Optional[Number]

abstract convert(value: str) Number[source]

Converts the given string value to the expected numeric type.

Parameters:

value (str) – The string value to be converted.

Returns:

The converted numeric value.

Return type:

Number

Raises:

InputConversionError – If the value cannot be converted to the expected numeric type.

validate_arguments() None[source]

Validates the range constraints provided to the NumberRangeModel.

validate_range(value: Number) None[source]

Validates that the given value is within the specified range.

Parameters:

value (Number) – The value to be validated.

Raises:

RangeError – If the value is outside the specified range.

validate_value(value: Number | str) Number[source]

Validates the given value and returns the validated value.

Parameters:

value (Number | str) – The value to be validated.

Returns:

The validated value.

Return type:

Number

Raises:
class mastermind.validation.base.semi_mutable.TrueFuse(value: Any)[source]

Bases: StateValidator[bool]

A StateValidator that can only be initialized to True or False, and can only be modified to True.

validate_modifications(new_value: Any) True[source]

Validates the modification to the value, ensuring it is set to True.

Parameters:

new_value (Any) – The new value to be set.

Raises:

InvalidModificationError – If the new value is not True.

validate_value(value: Any) bool[source]

Validates the initial value, ensuring it is a boolean.

Parameters:

value (Any) – The initial value.

Returns:

The validated value.

Return type:

bool

Raises:

TypeValidationError – If the value is not a boolean.

class mastermind.validation.base.validated_class.ValidatedClass[source]

Bases: ABC

An abstract base class that provides automatic validation of class attributes.

When accessing or modifying an attribute of a ValidatedClass instance, if the attribute is a StateValidator, its value will be automatically validated and returned or updated.