diff options
author | Anthon van der Neut <anthon@mnt.org> | 2017-08-15 15:59:38 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2017-08-15 15:59:38 +0200 |
commit | 74222db016e319460cbccc39ddad0180968490f5 (patch) | |
tree | 0769506c67cb2b4ee8564e048ec883d371f8fb4d /comments.py | |
parent | e9b75ce00c67f82cd61f738986b50ae85c89ebb9 (diff) | |
download | ruamel.yaml-74222db016e319460cbccc39ddad0180968490f5.tar.gz |
fix comment dumping0.15.31
Diffstat (limited to 'comments.py')
-rw-r--r-- | comments.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/comments.py b/comments.py index 00f57de..d77b981 100644 --- a/comments.py +++ b/comments.py @@ -250,13 +250,15 @@ class CommentedBase(object): if after_indent is None: after_indent = indent + 2 - if before and before[-1] == '\n': + if before and (len(before) > 1) and before[-1] == '\n': before = before[:-1] # strip final newline if there if after and after[-1] == '\n': after = after[:-1] # strip final newline if there start_mark = CommentMark(indent) c = self.ca.items.setdefault(key, [None, [], None, None]) - if before: + if before == '\n': + c[1].append(comment_token('', start_mark)) + elif before: for com in before.split('\n'): c[1].append(comment_token(com, start_mark)) if after: @@ -947,13 +949,13 @@ def dump_comments(d, name='', sep='.', out=sys.stdout): recurisively dump domments all but the toplevel preceded by the path in dotted form x.0.a """ - if isinstance(d, dict): + if isinstance(d, dict) and hasattr(d, 'ca'): if name: print(name) print(d.ca, file=out) # type: ignore for k in d: dump_comments(d[k], name=(name + sep + k) if name else k, sep=sep, out=out) - elif isinstance(d, list): + elif isinstance(d, list) and hasattr(d, 'ca'): if name: print(name) print(d.ca, file=out) # type: ignore |