Some EOL comments are not preserved
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
These EOL comments disappear on round-trip (which I found while coming up with some tests for my ruamel.yaml-based re-formatter):
---
string_next_line: # EOL comment before string gets lost
"this is a string bla bla
more text"
# this is a comment
folded_block_scalar_with_octothorpe: > # > EOL comment gets lost
# this is not a comment
# this is a comment
folded_chomp_strip_block_scalar_with_octothorpe: >- # > EOL comment gets lost
# this is not a comment
# this is a comment
folded_chomp_keep_block_scalar_with_octothorpe: >+ # > EOL comment gets lost
# this is not a comment
That first one is a known issue: you cannot have a comment between a key and its value.
The other three I can only explain as that I did forget folded scalar comment handling when I implemented the handling for literal scalar. I am not sure though if I push an extra release for that.
As I expected the last three only require minor changes, available in the handling of literal scalars with minor adjustments. They will be in 0.18 but if you can't wait it only affects two methods in
emitter.py
:See e.g. 418 for a duplicate of the first issue
The fix for folded scalars should be in 0.17.22+