MCPcopy
hub / github.com/WEIFENG2333/VideoCaptioner / _parse_value

Function _parse_value

videocaptioner/cli/config.py:239–259  ·  view source on GitHub ↗

Parse a string value into the correct Python type based on DEFAULTS.

(raw: str, key: str)

Source from the content-addressed store, hash-verified

237
238
239def _parse_value(raw: str, key: str) -> Any:
240 """Parse a string value into the correct Python type based on DEFAULTS."""
241 # Infer type from defaults
242 default_val = _get_nested(DEFAULTS, key)
243 if isinstance(default_val, bool):
244 if raw.lower() in ("true", "1", "yes"):
245 return True
246 if raw.lower() in ("false", "0", "no"):
247 return False
248 raise ValueError(f"Expected boolean for '{key}', got '{raw}' (use true/false)")
249 if isinstance(default_val, int):
250 try:
251 return int(raw)
252 except ValueError:
253 raise ValueError(f"Expected integer for '{key}', got '{raw}'")
254 if isinstance(default_val, float):
255 try:
256 return float(raw)
257 except ValueError:
258 raise ValueError(f"Expected number for '{key}', got '{raw}'")
259 return raw
260
261
262def save_config_value(key: str, value: str, config_path: Optional[Path] = None) -> None:

Callers 9

test_bool_trueMethod · 0.90
test_bool_falseMethod · 0.90
test_bool_invalidMethod · 0.90
test_intMethod · 0.90
test_int_invalidMethod · 0.90
test_stringMethod · 0.90
load_env_overridesFunction · 0.85
save_config_valueFunction · 0.85

Calls 1

_get_nestedFunction · 0.85

Tested by 7

test_bool_trueMethod · 0.72
test_bool_falseMethod · 0.72
test_bool_invalidMethod · 0.72
test_intMethod · 0.72
test_int_invalidMethod · 0.72
test_stringMethod · 0.72