File size: 813 Bytes
06c11b0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | """Utility helpers for validating and normalizing Robomme difficulty hints."""
from __future__ import annotations
from typing import Optional
VALID_DIFFICULTIES = {"easy", "medium", "hard"}
def normalize_robomme_difficulty(value: Optional[str]) -> Optional[str]:
"""Return a canonical difficulty string or ``None`` if no override was provided."""
if value is None:
return None
if not isinstance(value, str):
raise TypeError(
"difficulty must be a string (got "
f"{type(value).__name__!r})."
)
normalized = value.strip().lower()
if normalized not in VALID_DIFFICULTIES:
raise ValueError(
"Unsupported difficulty level. Available options: "
f"{sorted(VALID_DIFFICULTIES)}."
)
return normalized
|