def to_yaml(cls: Type['File'], instance: 'File') -> Mapping:
"""Represent the instance as YAML node.
Keyword arguments:
instance: The File to be represented.
Returns:
YAML representation of the instance.
"""
# Dump mod part
columns = (str(c).split('.')[-1] for c in Mod.__table__.columns)
yml = {f: getattr(instance.mod, f) for f in columns}
# Dump the file part
yml['file'] = attr.asdict(instance)
for field in ('mod',):
del yml['file'][field]
return yml
评论列表
文章目录