AttributError when using yaml_set_comment_before_after_key
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
I have an error when using yaml_set_comment_before_after_key and setting a "before" coment, when an "after" comment exist already.
from ruamel.yaml import YAML
yaml = YAML()
yaml_str = """
stages:
# some_comment
- test
- build
"""
data = yaml.load(yaml_str)
print(data.ca)
#Comment(start=None, items={ stages: [None, None, None, [CommentToken('# some_comment\n', line: 2, col: 2)]]})
data.yaml_set_comment_before_after_key("stages", before="test2")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-a616e96e7f6f> in <module>
12 data = yaml.load(yaml_str)
13 data.ca
---> 14 data.yaml_set_comment_before_after_key("stages", before="test2")
~/.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)
396 elif before:
397 for com in before.split('\n'):
--> 398 c[1].append(comment_token(com, start_mark))
399 if after:
400 start_mark = CommentMark(after_indent)
AttributeError: 'NoneType' object has no attribute 'append'
Thanks for reporting this is fixed in 0.17.15