Skip to content

5. Value Resolution and Type Casting Implementation

Date: 2025-01-23

Status

Accepted

Context

Implementation of value resolution, default handling, and type casting requires precise specification to ensure consistent behavior across the configuration system.

Decision

Component Specifications

  1. Default Value Resolution (default): - Initial state: NOT_SET - Resolution hierarchy:

    • Return provided value if not NOT_SET
    • Return NOT_SET if no value provided
    • Guarantees value presence when specified
    • Ensures type correctness when cast is enabled
  2. Type Casting Implementation (cast): - Requires callable object or cast is skipped - Execution conditions:

    • Processes non-NOT_SET values
    • If value is NOT_SET, then it uses default value
    • Throws TypeError on failed casting operations
  3. Value Injection (value): - Direct configuration injection mechanism - Resolution logic:

    • If NOT_SET: utilize default value chain
    • If default is NOT_SET: uses NOT_SET
    • Cast implementation:
    • Skip if value is NOT_SET
    • Execute cast operation if cast is enabled

Resolution Algorithm

  1. Parameter initialization: - Load value, cast, and default parameters
  2. Value resolution:
if value != NOT_SET:
    result = value
elif default != NOT_SET:
    result = default
else:
    result = NOT_SET
  1. Cast execution: - Skip if result is NOT_SET - Execute cast operation if enabled

Consequences

The implementation provides granular control over value resolution and type casting while maintaining predictable behavior patterns. The complexity is justified by the flexibility requirements of the configuration system.