summaryrefslogtreecommitdiff
path: root/comments.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-08-10 14:39:47 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-08-10 14:39:47 +0200
commit4428f383e3377642857a3e929a7c4ffcbbb6ced3 (patch)
tree301aa7abfea7aa3b0e52bce4ccf0ce6cbd163dfe /comments.py
parent1ba1892b0a510ab4b3be7788b98ae54450d7c24f (diff)
downloadruamel.yaml-4428f383e3377642857a3e929a7c4ffcbbb6ced3.tar.gz
fix issue #102: comment disappear after empty flow-style sequence
**When this fix solves the reported problem, please close this issue.**
Diffstat (limited to 'comments.py')
-rw-r--r--comments.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/comments.py b/comments.py
index 1e2bf82..8f69d0e 100644
--- a/comments.py
+++ b/comments.py
@@ -8,6 +8,7 @@ these are not really related, formatting could be factored out as
a separate base
"""
+import sys
import copy
from collections import MutableSet, Sized, Set
@@ -938,3 +939,22 @@ class CommentedSet(MutableSet, CommentedMap):
def __repr__(self):
# type: () -> str
return 'set({0!r})'.format(self.odict.keys())
+
+
+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 name:
+ print(name)
+ print(d.ca, file=out)
+ for k in d:
+ dump_comments(d[k], name=name + sep + k if name else k, sep=sep, out=out)
+ elif isinstance(d, list):
+ if name:
+ print(name)
+ print(d.ca, file=out)
+ for idx, k in enumerate(d):
+ dump_comments(k, name=name + sep + str(idx) if name else k, sep=sep, out=out)