MCPcopy Create free account
hub / github.com/SooLab/CGFormer / _decode_cfg_value

Function _decode_cfg_value

utils/config.py:91–117  ·  view source on GitHub ↗

Decodes a raw config value (e.g., from a yaml config files or command line argument) into a Python object.

(v)

Source from the content-addressed store, hash-verified

89
90
91def _decode_cfg_value(v):
92 """Decodes a raw config value (e.g., from a yaml config files or command
93 line argument) into a Python object.
94 """
95 # All remaining processing is only applied to strings
96 if not isinstance(v, str):
97 return v
98 # Try to interpret `v` as a:
99 # string, number, tuple, list, dict, boolean, or None
100 try:
101 v = literal_eval(v)
102 # The following two excepts allow v to pass through when it represents a
103 # string.
104 #
105 # Longer explanation:
106 # The type of v is always a string (before calling literal_eval), but
107 # sometimes it *represents* a string and other times a data structure, like
108 # a list. In the case that v represents a string, what we got back from the
109 # yaml parser is 'foo' *without quotes* (so, not '"foo"'). literal_eval is
110 # ok with '"foo"', but will raise a ValueError if given 'foo'. In other
111 # cases, like paths (v = 'foo/bar' and not v = '"foo/bar"'), literal_eval
112 # will raise a SyntaxError.
113 except ValueError:
114 pass
115 except SyntaxError:
116 pass
117 return v
118
119
120def _check_and_coerce_cfg_value_type(replacement, original, key, full_key):

Callers 1

merge_cfg_from_listFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected