2018-07-24 11:28:53 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from ruamel.yaml import YAML, yaml_object
|
|
|
|
|
|
|
|
|
|
|
|
# typing.NamedTuple is incompatible with yaml.register_class.
|
|
|
|
# dataclasses.dataclass is compatible.
|
|
|
|
# So use the latter.
|
|
|
|
|
|
|
|
# __init__-less classes are also compatible with yaml.register_class.
|
|
|
|
|
|
|
|
|
|
|
|
yaml = YAML()
|
|
|
|
|
|
|
|
|
2018-07-25 12:01:58 +00:00
|
|
|
def register_config(cls):
|
2018-07-24 11:28:53 +00:00
|
|
|
# https://stackoverflow.com/a/51497219/2683842
|
|
|
|
# YAML.register_class(cls) has only returned cls since 2018-07-12.
|
|
|
|
return yaml_object(yaml)(
|
|
|
|
dataclass(cls)
|
|
|
|
)
|