supercollections prevents dumping back as yaml
a simple usecase might be to call yaml.safe_dump back on any variables loaded with this plugin, but the lack of any encoders causes a crash. A dump has the custom objects built in:
(Pdb) yaml.dump(contribution["notes"])
'!!python/object/new:super_collections.SuperList\nlistitems:\n- MET/sqrt(Ht) signal shape\n- !!python/object/new:super_collections.SuperList\n listitems:\n - why are smaller mass splittings harder? Is this due to chargino decay products?\n - Check how MET and Ht differ between signals\n'
as opposed to the crash with safe_dump
(Pdb) yaml.safe_dump(contribution["notes"])
*** yaml.representer.RepresenterError: ('cannot represent an object', ['MET/sqrt(Ht) signal shape', ['why are smaller mass splittings harder? Is this due to chargino decay products?', 'Check how MET and Ht differ between signals']])
It would be really nice if the mkdocs-macros didn't just give SuperDict/SuperLists which makes things a bit harder, and somewhat unexpected when one is just providing yaml metadata in the frontmatter. The easiest solution I find is this
import yaml
import super_collections
def custom_representer(dumper, data):
"""Convert custom objects into YAML serializable format."""
if isinstance(data, super_collections.SuperList):
return dumper.represent_list(data)
elif isinstance(data, super_collections.SuperDict):
return dumper.represent_dict(data)
else:
return dumper.represent_str(str(data))
# Register the custom representer for unknown objects
yaml.add_multi_representer(object, custom_representer)
Welcome to this project and thank you!
In principle a SuperDict should be have exactly as a dictionary. If it doesn't then it might be an issue with it.
Cross referencing: fralau/super-collections/issues/7
A similar issue has just been fixed by fixing a CustomEncoder in SuperCollections with JSON, so I am now a little more familiar.
@kratsg I would need to examples where this happens, so that I can think with it. Could you give me more information?
I wish I could tell you, as I migrated to using inline-data on the markdown pages instead. I'm not fully sure I recall anymore. I think I had some data in a yaml file that I was trying to load and generate the markdown content on the fly.
This should be solved with SuperCollections v0.5.7.
See: https://github.com/fralau/super-collections/issues/7
@kratsg Could you please test if that happens again?
Fixed for me for all of the projects I've tested so far.