summaryrefslogtreecommitdiff
path: root/representer.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2021-08-21 14:20:29 +0200
committerAnthon van der Neut <anthon@mnt.org>2021-08-21 14:20:29 +0200
commitd97574a94bca9a6b62511ee14bb633a5fdc2e32e (patch)
tree70f59ec02c9336f107c18fd38f2c017dc42de1af /representer.py
parent15e7b487ef04fe617ec695cf7980763b0b8e170f (diff)
downloadruamel.yaml-d97574a94bca9a6b62511ee14bb633a5fdc2e32e.tar.gz
fix for issue 393
Diffstat (limited to 'representer.py')
-rw-r--r--representer.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/representer.py b/representer.py
index a27f457..f0aea0a 100644
--- a/representer.py
+++ b/representer.py
@@ -26,6 +26,7 @@ from ruamel.yaml.scalarint import ScalarInt, BinaryInt, OctalInt, HexInt, HexCap
from ruamel.yaml.scalarfloat import ScalarFloat
from ruamel.yaml.scalarbool import ScalarBoolean
from ruamel.yaml.timestamp import TimeStamp
+from ruamel.yaml.anchor import Anchor
import datetime
import sys
@@ -1080,6 +1081,17 @@ class RoundTripRepresenter(SafeRepresenter):
anchor = None
return SafeRepresenter.represent_bool(self, data, anchor=anchor)
+ def represent_yaml_object(self, tag, data, cls, flow_style=None):
+ if hasattr(data, '__getstate__'):
+ state = data.__getstate__()
+ else:
+ state = data.__dict__.copy()
+ anchor = state.pop(Anchor.attrib, None)
+ res = self.represent_mapping(tag, state, flow_style=flow_style)
+ if anchor is not None:
+ res.anchor = anchor
+ return res
+
RoundTripRepresenter.add_representer(type(None), RoundTripRepresenter.represent_none)