HyperPyYAML
HyperPyYAML copied to clipboard
Saving config files with !new tags
Hello,
I have the following code (a MWE - minimum working example), where I want to dump a config with a !new
instatiation.
yaml_string = """
foo: !new:collections.Counter
a: 4
bar: !ref <foo>
baz: !copy <foo>
"""
loaded_yaml = load_hyperpyyaml(yaml_string)
from hyperpyyaml import dump_hyperpyyaml
# Importing the StringIO module.
from io import StringIO
dump_hyperpyyaml(loaded_yaml, StringIO())
This fails with the following
RepresenterError Traceback (most recent call last)
[<ipython-input-6-c8804319bfb8>](https://localhost:8080/#) in <cell line: 14>()
12 from io import StringIO
13
---> 14 dump_hyperpyyaml(loaded_yaml, StringIO())
9 frames
[/usr/local/lib/python3.10/dist-packages/ruamel/yaml/representer.py](https://localhost:8080/#) in represent_undefined(self, data)
343
344 def represent_undefined(self, data: Any) -> None:
--> 345 raise RepresenterError(f'cannot represent an object: {data!s}')
346
347
RepresenterError: cannot represent an object: Counter({'a': 4})
Neither the docs, nor the given Colab notebook contains an example of dumping with the !new
tag. How could this be done?