MCPcopy
hub / github.com/google/python-fire / _ParseValue

Function _ParseValue

fire/core.py:959–988  ·  view source on GitHub ↗

Parses value, a string, into the appropriate type. The function used to parse value is determined by the remaining arguments. Args: value: The string value to be parsed, typically a command line argument. index: The index of the value in the function's argspec. arg: The name of the

(value, index, arg, metadata)

Source from the content-addressed store, hash-verified

957
958
959def _ParseValue(value, index, arg, metadata):
960 """Parses value, a string, into the appropriate type.
961
962 The function used to parse value is determined by the remaining arguments.
963
964 Args:
965 value: The string value to be parsed, typically a command line argument.
966 index: The index of the value in the function's argspec.
967 arg: The name of the argument the value is being parsed for.
968 metadata: Metadata about the function, typically from Fire decorators.
969 Returns:
970 value, parsed into the appropriate type for calling a function.
971 """
972 parse_fn = parser.DefaultParseValue
973
974 # We check to see if any parse function from the fn metadata applies here.
975 parse_fns = metadata.get(decorators.FIRE_PARSE_FNS)
976 if parse_fns:
977 default = parse_fns['default']
978 positional = parse_fns['positional']
979 named = parse_fns['named']
980
981 if index is not None and 0 <= index < len(positional):
982 parse_fn = positional[index]
983 elif arg in named:
984 parse_fn = named[arg]
985 elif default is not None:
986 parse_fn = default
987
988 return parse_fn(value)

Callers 2

_ParseFnFunction · 0.85
_ParseArgsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected