Closed ROFLailXGOD closed 4 years ago
Yeah, it's a feature in this module, and not in YAML format itself.
See https://github.com/mk-fg/pretty-yaml/#warning - which is the first section of the README that says:
Warning
Prime goal of this module is to produce human-readable output that can be easily
manipulated and re-used, but maybe with some occasional caveats.
One good example of such "caveat" is that e.g. {'foo': '123'} will serialize to
foo: 123, which for PyYAML would be a bug, as 123 will then be read back as an
integer from that, but here it's a feature.
So please do not rely on the thing to produce output that can always be
deserialized exactly to what was exported, at least - use PyYAML (e.g. with
options from the next section) for that.
There a plenty of such cases here, which I occasionally fix, but it'll never be safe to use this output for serialization purposes.
You can use regular pyyaml module for that though, as far as I know that module is designed to produce correct output, regardless of how it looks. Iirc there should be some option suggestions for making its output nicer in the README too.
So, recently I've tried this module to generate .yml files and came across an issue. If a line starts with a percentage sign, then this line ends up unquotted in the generated .yml file:
The problem occurs when you try to load it with
yaml.safe_load()
which results in:I'm really not sure if it is supposed to be like that (bug or feature?), because I'm not really familiar with this format yet and there might be different specifications, but if former then all we need to change is add % in this line, I think.