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 = ":")
| 118 | |
| 119 | |
| 120 | def 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 | |
| 143 | def format_table(*, headings: list[str], rows: list[list[str]]) -> str: |
no outgoing calls
no test coverage detected