MCPcopy Create free account
hub / github.com/VisionRush/DeepFakeDefenders / _decode_cfg_value

Method _decode_cfg_value

toolkit/yacs.py:405–440  ·  view source on GitHub ↗

Decodes a raw config value (e.g., from a yaml config files or command line argument) into a Python object. If the value is a dict, it will be interpreted as a new CfgNode. If the value is a str, it will be evaluated as literals. Otherwise it is returned as-i

(cls, value)

Source from the content-addressed store, hash-verified

403
404 @classmethod
405 def _decode_cfg_value(cls, value):
406 """
407 Decodes a raw config value (e.g., from a yaml config files or command
408 line argument) into a Python object.
409
410 If the value is a dict, it will be interpreted as a new CfgNode.
411 If the value is a str, it will be evaluated as literals.
412 Otherwise it is returned as-is.
413 """
414 # Configs parsed from raw yaml will contain dictionary keys that need to be
415 # converted to CfgNode objects
416 if isinstance(value, dict):
417 return cls(value)
418 # All remaining processing is only applied to strings
419 if not isinstance(value, str):
420 return value
421 # Try to interpret `value` as a:
422 # string, number, tuple, list, dict, boolean, or None
423 try:
424 value = literal_eval(value)
425 # The following two excepts allow v to pass through when it represents a
426 # string.
427 #
428 # Longer explanation:
429 # The type of v is always a string (before calling literal_eval), but
430 # sometimes it *represents* a string and other times a data structure, like
431 # a list. In the case that v represents a string, what we got back from the
432 # yaml parser is 'foo' *without quotes* (so, not '"foo"'). literal_eval is
433 # ok with '"foo"', but will raise a ValueError if given 'foo'. In other
434 # cases, like paths (v = 'foo/bar' and not v = '"foo/bar"'), literal_eval
435 # will raise a SyntaxError.
436 except ValueError:
437 pass
438 except SyntaxError:
439 pass
440 return value
441
442
443load_cfg = (

Callers 2

merge_from_listMethod · 0.95
_merge_a_into_bFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected