Overall this library is very impressive, Enabling surgery and round-tripping on YAML as well as it does is no small feat. But...
Either line wrap should be disabled in the dumper in rt mode, or the code used to do it should be smart enough to never alter whitespace inside string literals. I favor the former for simplicity and true round-tripping
I've attached two files that are self-contained sections from a large and complex YAML document that I round-tripped; base.yaml is before, roundtrip.yaml is after. This was my read invocation:
yaml = YAML(typ="rt")
yaml.preserve_quotes = True
with open(source_path, "r", encoding="utf-8") as fp:
root = yaml.load(fp)
```
You'll observe that the 'local enum ' token gets clobbered by the line wrapper. This was an unpleasant surprise and could have caused bugs in my client code. I was able to prevent the misbehavior with this:
# Disable line wrapping in the output
# Without this setting, the YAML dumper's line-wrapping code may clobber
# tokens in long string lists like Yes/No declarations because it doesn't
# know that string literal should be immutable.
yaml.width = 10**9
```
But I shouldn't have had to do that. If you advertise a round-trip mode, it should actually fully round-trip.
For the same trason, I think preserve quotes should default to True in rt mode.
Somehow I missed an attachment. Here it is.