misc.py 476 B

1234567891011121314
  1. import yaml
  2. def yaml_coerce(value):
  3. """
  4. Pass in a string dictionary and convert it into proper python dictionary
  5. """
  6. if isinstance(value, str):
  7. # create a tiny snippet of YAML, with key=dummy, and val=value, then load the YAML into
  8. # a pure Pythonic dictionary. Then, we read off the dummy key from the coversion to get our
  9. # final result
  10. return yaml.load(f'dummy: {value}', Loader=yaml.SafeLoader)['dummy']
  11. return value