Menu

#546 Trailing whitespaces in some generated YAML outputs

open
nobody
None
minor
bug
2025-08-31
2025-06-09
No

Hey there,
First issue open here (and first in Sourceforge) so I hope I got everything right.

import ruaml.yaml, sys
ruamel.yaml.YAML().dump([f"{'a' * 77} {'a' * 2}"], sys.stdout)

output

- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 
  aa

(note the space at the end of the first line)

expected

- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  aa

(no trailing whitespace)

I've played with numbers (77 and 2) and it seems that sometimes, there's a space, and sometimes (such as 78 1) there's not.

(I'll do my best to try and remember to come here and see the discussion but I can't promise anything)

Discussion

  • Alexei Znamensky

    Hi, I came to open a ticket for the same thing, glad it has been reported before. I maintain a tool to support developers of Ansible plugins, called andebox. One of the features the tool provides is reformatting the YAML texts containing documentation, within a Python file, and ruamel.yaml is used for that.
    The latest updates (from 0.18.12 to 0.18.14) have broken tests that were working before - the word wrapping logic has changed but that's OK, I reckon the new logic made more sense, so I adjusted the expected result of my tests. However, I kept having errors. I just found out the reason why, see the excerpt of my test result (I added | markers around the lines):

    ----------------------------- Captured stdout call -----------------------------
    ACTUAL
    |short_description: Test plugin|
    |description:|
    |  - Lorem ipsum dolor sit amet |
    |    consectetur adipiscing elit quisque |
    |    faucibus.|
    |options: {}|
    EXPECTED
    |short_description: Test plugin|
    |description:|
    |  - Lorem ipsum dolor sit amet|
    |    consectetur adipiscing elit quisque|
    |    faucibus.|
    |options: {}|
    

    Note the first and second lines of the description element with the trailing spaces by the end of the content. In this test I configured ruamel.yaml to wrap the YAML content at length 40.

    So, for now, I am sticking to 0.18.12, but it would be nice to see this fixed.

    Thank you very much for your work on ruamel.yaml, it is an awesome library.

     
  • Alexei Znamensky

    Actually, I can confirm that this behaviour was introduced in 0.18.13, so definitely sticking to 0.18.12 for now

     
  • Dmitry Salamatov

    Post awaiting moderation.
  • Alexei Znamensky

    Hi there, I can confirm that 0.18.15 is passing the tests (in the andebox project).

     

Log in to post a comment.