MCPcopy Create free account
hub / github.com/RingBDStack/GDAP / parse_numeric_n_bool_cl_kwargs

Function parse_numeric_n_bool_cl_kwargs

seq2seq/utils.py:590–612  ·  view source on GitHub ↗

Parse an argv list of unspecified command line args to a dict. Assumes all values are either numeric or boolean in the form of true/false.

(unparsed_args: List[str])

Source from the content-addressed store, hash-verified

588
589
590def parse_numeric_n_bool_cl_kwargs(unparsed_args: List[str]) -> Dict[str, Union[int, float, bool]]:
591 """
592 Parse an argv list of unspecified command line args to a dict.
593 Assumes all values are either numeric or boolean in the form of true/false.
594 """
595 result = {}
596 assert len(unparsed_args) % 2 == 0, f"got odd number of unparsed args: {unparsed_args}"
597 num_pairs = len(unparsed_args) // 2
598 for pair_num in range(num_pairs):
599 i = 2 * pair_num
600 assert unparsed_args[i].startswith("--")
601 if unparsed_args[i + 1].lower() == "true":
602 value = True
603 elif unparsed_args[i + 1].lower() == "false":
604 value = False
605 else:
606 try:
607 value = int(unparsed_args[i + 1])
608 except ValueError:
609 value = float(unparsed_args[i + 1]) # this can raise another informative ValueError
610
611 result[unparsed_args[i][2:]] = value
612 return result
613
614
615def write_txt_file(ordered_tgt, path):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected