Unable to dump mutated TimeStamp objects
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
I observed that mutating TimeStamp objects produced by ruamel.yaml results in data that ruamel.yaml cannot dump.
To reproduce run the following code using the latest version (0.16.12):
from ruamel.yaml import YAML
from io import StringIO
out = StringIO()
yaml = YAML()
t = yaml.load('2020-11-10 18:00:00+00:00')
print(repr(t))
t2 = t.replace(second=0)
print(repr(t2))
yaml.dump(t2, out)
This will fail with AttributeError: 'TimeStamp' object has no attribute '_yaml'.
I had more or less expected that the fall-through to
datetime.datetime.replace()would return adatetime.datetimeinstance, but instead it doesreturn type(self)(....)So the thing to do is add a replace that properly copies the
_yamlattribute.Fixed in 0.16.13, thanks reporting
Fixed in 0.16.13, thanks reporting
Awesome, thanks!