Module

config.validators

Configuration validation without external dependencies.

Provides type-safe configuration validation with helpful error messages, following Bengal's minimal dependencies and single-responsibility principles.

Classes

ConfigValidationError
Raised when configuration validation fails.
0

Raised when configuration validation fails.

Inherits from ValueError
ConfigValidator
Validates configuration with helpful error messages. Single-responsibility validator class that ch…
6

Validates configuration with helpful error messages.

Single-responsibility validator class that checks:

  • Type correctness (bool, int, str)
  • Value ranges (min/max)
  • Required fields
  • Type coercion where sensible

Methods 1

validate
Validate configuration and return normalized version.
2 dict[str, Any]
def validate(self, config: dict[str, Any], source_file: Path | None = None) -> dict[str, Any]

Validate configuration and return normalized version.

Parameters 2
config dict[str, Any]

Raw configuration dictionary

source_file Path | None

Optional source file for error context

Returns

dict[str, Any]

Validated and normalized configuration

Internal Methods 5
_flatten_config
Flatten nested configuration for validation. Supports both: - Flat: {parallel:…
1 dict[str, Any]
def _flatten_config(self, config: dict[str, Any]) -> dict[str, Any]

Flatten nested configuration for validation.

Supports both:

  • Flat: {parallel: true, title: "Site"}
  • Nested: {build: {parallel: true}, site: {title: "Site"}}
Parameters 1
config dict[str, Any]
Returns

dict[str, Any]

_validate_types
Validate and coerce config value types.
1 list[str]
def _validate_types(self, config: dict[str, Any]) -> list[str]

Validate and coerce config value types.

Parameters 1
config dict[str, Any]
Returns

list[str]

_validate_ranges
Validate numeric ranges.
1 list[str]
def _validate_ranges(self, config: dict[str, Any]) -> list[str]

Validate numeric ranges.

Parameters 1
config dict[str, Any]
Returns

list[str]

_validate_dependencies
Validate field dependencies and logical consistency.
1 list[str]
def _validate_dependencies(self, config: dict[str, Any]) -> list[str]

Validate field dependencies and logical consistency.

Parameters 1
config dict[str, Any]
Returns

list[str]

_print_errors
Print formatted validation errors.
2 None
def _print_errors(self, errors: list[str], source_file: Path | None = None) -> None

Print formatted validation errors.

Parameters 2
errors list[str]
source_file Path | None