ml_switcheroo.testing.fuzzer.parser

Type Hint Parser and Recursive Generation Logic.

This module processes string type hints (e.g. List[Array[‘N’]]) and generates conforming data structures for runtime fuzzing.

It includes logic to: 1. Parse nested generic types. 2. Resolve symbolic shape constraints. 3. Respect semantic constraints (min, max, options). 4. Infer generation strategy from default values when explicit hints are erased.

Functions

get_fallback_base_value(→ Any)

Returns a minimal valid value to terminate recursion when depth limit is reached.

generate_from_hint(→ Any)

Recursively parses a type string and generates conforming data.

Module Contents

ml_switcheroo.testing.fuzzer.parser.get_fallback_base_value(type_str: str, base_shape: Tuple[int, Ellipsis]) Any

Returns a minimal valid value to terminate recursion when depth limit is reached.

Parameters:
  • type_str – The target type hint.

  • base_shape – Default shape for array fallbacks.

Returns:

Safe fallback value (0, empty list, etc).

ml_switcheroo.testing.fuzzer.parser.generate_from_hint(type_str: str, base_shape: Tuple[int, Ellipsis], depth: int, max_depth: int, symbol_map: Dict[str, int], constraints: Dict[str, Any] | None = None) Any

Recursively parses a type string and generates conforming data.

If type hints are generic (“Any”), it attempts to infer the type logic from the default value provided in constraints.

Parameters:
  • type_str – The type hint string to parse.

  • base_shape – Default shape helper.

  • depth – Current recursion depth.

  • max_depth – Limit for recursion.

  • symbol_map – Shared context for dimension symbols (‘N’).

  • constraints – Semantic constraints (min, max, options, default).

Returns:

Generated data structure.