MCPcopy Create free account
hub / github.com/apple/axlearn / parse_kv_flags

Function parse_kv_flags

axlearn/cloud/common/utils.py:120–140  ·  view source on GitHub ↗

Parses sequence of k:v into a dict. Args: kv_flags: A sequence of strings in the format "k:v". If a key appears twice, the last occurrence "wins". delimiter: The separator between the key and value. Returns: A dict where keys and values are parsed from "

(kv_flags: Sequence[str], *, delimiter: str = ":")

Source from the content-addressed store, hash-verified

118
119
120def parse_kv_flags(kv_flags: Sequence[str], *, delimiter: str = ":") -> dict[str, str]:
121 """Parses sequence of k:v into a dict.
122
123 Args:
124 kv_flags: A sequence of strings in the format "k:v". If a key appears twice, the last
125 occurrence "wins".
126 delimiter: The separator between the key and value.
127
128 Returns:
129 A dict where keys and values are parsed from "k:v".
130
131 Raises:
132 ValueError: If a member of `kv_flags` isn't in the format "k:v".
133 """
134 metadata = {}
135 for kv in kv_flags:
136 parts = kv.split(delimiter, maxsplit=1)
137 if len(parts) != 2:
138 raise ValueError(f"Expected key{delimiter}value, got {kv}")
139 metadata[parts[0]] = parts[1]
140 return metadata
141
142
143def format_table(*, headings: list[str], rows: list[list[str]]) -> str:

Callers 8

from_flagsMethod · 0.90
from_flagsMethod · 0.90
from_flagsMethod · 0.90
__init__Method · 0.90
from_specMethod · 0.90
from_specMethod · 0.90
from_specMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected