MCPcopy Create free account
hub / github.com/InsForge/InsForge / parse_kv_pairs

Function parse_kv_pairs

examples/python-ml-experiment-tracker/tracker/cli.py:74–98  ·  view source on GitHub ↗

Parse KEY=VALUE strings into a typed dict, coercing bool/int/float where applicable.

(pairs: tuple[str, ...])

Source from the content-addressed store, hash-verified

72
73
74def parse_kv_pairs(pairs: tuple[str, ...]) -> dict[str, Any]:
75 """Parse KEY=VALUE strings into a typed dict, coercing bool/int/float where applicable."""
76 result: dict[str, Any] = {}
77 for pair in pairs:
78 if "=" not in pair:
79 raise click.BadParameter(
80 f"Expected KEY=VALUE, got: {pair!r}",
81 param_hint="--params/--metrics",
82 )
83 key, _, raw = pair.partition("=")
84 key = key.strip()
85 raw = raw.strip()
86 if raw.lower() == "true":
87 result[key] = True
88 elif raw.lower() == "false":
89 result[key] = False
90 else:
91 try:
92 result[key] = int(raw)
93 except ValueError:
94 try:
95 result[key] = float(raw)
96 except ValueError:
97 result[key] = raw
98 return result
99
100
101def now_iso() -> str:

Callers 1

cmd_logFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected