The following is not working for me, with Python 3.4.7, ruamel.yaml version 0.15.35:
import sys
import enum
import ruamel.yaml
from ruamel.yaml import yaml_object
yaml = ruamel.yaml.YAML()
@yaml_object(yaml)
class Speed(enum.IntEnum):
Reverse = 0
Neutral = 1
Low = 2
Drive = 3
Park = 999
print("Neutral:", repr(Speed.Neutral))
yaml.dump(Speed.Neutral, sys.stdout)
I get a totally reasonable repr
:
Neutral: <Speed.Neutral: 1>
but the .dump()
raises:
ruamel.yaml.representer.RepresenterError: cannot represent an object: <enum 'Speed'>
If enum
's are not supported, is there something I can do to extend the enum
class I am using (or the subclass enum.IntEnum
I have created), e.g. a dunder method?