Hi,
This is a bug I actually found with the standard Python yaml module (aka. python-yaml on Debian). When I tried reporting this bug back in July, I was informed that yaml was no longer maintained and that I should investigate ruamel.yaml.
So, I've taken my test case that I wrote then, and ported it over to ruamel.yaml… it seems I'm able to reproduce the same bug. The situation is this: we want to be able to represent strings that have multi-line values in a human-readable form. That is:
a_value: |
Like this.
Each line kept separate, with no control characters obscuring it.
not like this:
a_value: "This is what we typically get\nNearly impossible to read."
I've been able to reproduce this problem on a couple of versions of ruamel.yaml, including the Debian Jessie package and the latest on pypi (0.15.34).
The attached test case produces the following output:
RC=0 stuartl@rikishi ~ $ python2 /tmp/pyyaml.py
/home/stuartl/.local/lib64/python2.7/site-packages/ruamel/yaml/resolver.py:277: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if value == u'':
"\nThis is a multi-line\n string that has some characters\nthat break pyyaml, such
as these:\n\n \xB9\u2082\xB3\u2084\u2075\u2086\u2077\u2088\n"
Python 3 is the same, although we avoid a UnicodeWarning there. I was expecting output like this:
|
This is a multi-line
string that has some characters
that break pyyaml, such as these:
¹₂³₄⁵₆⁷₈
Regards,
Stuart Longland
(originally posted on 2017-11-07 at 07:02:45 by Stuart Longland <Stuart Longland@bitbucket>)
First of all apologies for the late reply, I am finally catching up with things a bit. This is more of an incorrect usage post and as such I would prefer if you had posted a question tagged
ruamel.yamlon StackOverflow.The things easily solved (even with the version available last November):
gives:
There are a few things to take note of:
ruamel.yamlfrom __future__ import unicode_literalsmarking a Python string withu, as yourbreak_stringis, is superfluousprint_functionif you import from__future__anyway. For single argumentprintusage that doesn't make much difference, but a soon as you add a second one, Python2 will give you a tuple if you don't importprint_functionprint()adds an extra newline behind the one which PyYAML puts at the end of the document.(originally posted on 2018-08-13 at 06:29:22)
None
(originally posted on 2018-08-13 at 06:29:51)
(originally posted on 2018-08-13 at 06:30:01)