Open trim21 opened 1 year ago
Current workaround for this specific case:
yaml.SafeDumper.add_representer(
Status,
yaml.representer.SafeRepresenter.represent_str,
)
It may need to be repeated for the all the various dumpers that may be used used, and it unfortunately does not work with StrEnum
instead of Status
Just use add_multi_representer for the base class, so all sub-classes will use the base representer:
yaml.SafeDumper.add_multi_representer(
StrEnum,
yaml.representer.SafeRepresenter.represent_str,
)
Just use add_multi_representer for the base class, so all sub-classes will use the base representer:
yaml.SafeDumper.add_multi_representer( StrEnum, yaml.representer.SafeRepresenter.represent_str, )
would be nice to have this included in pyyaml library
hope pyyaml can support
enum.StrEnum
element of StrEnum is consider str in Python
stdlib json support this:
print(json.dumps({'status': Status.A}))