Skip to content

Commit

Permalink
Fix parsing function in cli_arguments.py
Browse files Browse the repository at this point in the history
The 'parse_key_value_list' function in cli_arguments.py file was refactored to accommodate a different input and more accurate return type. Previously, it was looking for a list of dictionaries as an input but that has been revised to accept a list of strings with the format "KEY=VALUE". This function now returns a dict of split key-value options. The imported __future__ annotations has also been added in this version.
  • Loading branch information
jiridanek committed Sep 14, 2023
1 parent 7f4a43a commit 15c24b9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/yacfg/cli/cli_arguments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import argparse
import json
import re
Expand Down Expand Up @@ -46,16 +48,17 @@ def split_key_value(item: str) -> Tuple[str, str]:
return key, value


def parse_key_value_list(items: List[Dict[str, str]]) -> Dict[str, str]:
"""Convert a list of dictionaries into a single dictionary.
def parse_key_value_list(items: list[str]) -> dict[str, str]:
"""Split all KEY=VALUE items in a list of such options.
:param items: list of KEY=VALUE string options to be split.
:param items: List of dictionaries.
:type items: list[dict]
:raises ValueError: if any option cannot be split.
:return: Merged dictionary with key-value pairs from all dictionaries.
:rtype: dict
:return: a map of KEY: VALUE split options
"""
return {k: v for item in items for k, v in item.items() if isinstance(item, dict)}
result = dict([split_key_value(item) for item in items])
return result


parser = argparse.ArgumentParser(
Expand Down

0 comments on commit 15c24b9

Please sign in to comment.