AttributError when using yaml_set_comment_before_after_key with "\n"
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
First of all, thanks for the library and thanks a lot for the quick recent fixes, this is really appreciated!!
Further to my last ticket (https://sourceforge.net/p/ruamel-yaml/tickets/397/), It's working perfectly fine for any comments except "\n", it looks like it's entering a different condition.
from ruamel.yaml import YAML
yaml = YAML()
yaml_str = """
stages:
# some_comment
- test
- build
"""
data = yaml.load(yaml_str)
data.yaml_set_comment_before_after_key("stages", before="\n")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-19-8808c27d78ca> in <module>
14 #Comment(start=None, items={ stages: [None, None, None, [CommentToken('# some_comment\n', line: 2, col: 2)]]})
15
---> 16 data.yaml_set_comment_before_after_key("stages", before="\n")
~/.pyenv/versions/3.8.6/envs/gitlabci-jsonschema-lint/lib/python3.8/site-packages/ruamel/yaml/comments.py in yaml_set_comment_before_after_key(self, key, before, indent, after, after_indent)
393 c = self.ca.items.setdefault(key, [None, [], None, None])
394 if before == '\n':
--> 395 c[1].append(comment_token("", start_mark))
396 elif before:
397 if c[1] is None:
AttributeError: 'NoneType' object has no attribute 'append'
Should be fixed in 0.17.16
Do you have any estimate on when 0.17.16 will be released? just asking so that I know if it's a matter of days or if I should find a workaround .
Again, Thanks a lot for the support
I though I had already pushed that to pypi as I wrote that, but somehow it hadn't and now the terminal window is no longer open to see what kind of error caused that. Thanks for reminding
Works like a charm, thanks