pyyaml icon indicating copy to clipboard operation
pyyaml copied to clipboard

safe_dump should dump frozenset as !!set

Open bmccutchon opened this issue 6 years ago • 1 comments

This works:

>>> yaml.safe_dump(set())
'!!set {}\n'

This also works, though it's kind of weird:

>>> yaml.dump(frozenset())
'!!python/object/apply:__builtin__.frozenset\n- []\n'

This doesn't work:

>>> yaml.safe_dump(frozenset())
# yaml.representer.RepresenterError: cannot represent an object: frozenset([])

bmccutchon avatar Jun 28 '19 22:06 bmccutchon

Is there any workaround/parameter that allows to do this without manually turning all frozensets to regular sets?

mschilli87 avatar Mar 28 '25 09:03 mschilli87