summaryrefslogtreecommitdiff
path: root/representer.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-11-01 15:41:15 +0100
committerAnthon van der Neut <anthon@mnt.org>2018-11-01 15:41:15 +0100
commite63c1e186f88812d705de8f572373d2abe5f195b (patch)
treed2ca9500cab4cadd16d8b75852a23f12a359966e /representer.py
parent82a72a27c6ba866878fdebe7a70bd4a86f54e81d (diff)
downloadruamel.yaml-e63c1e186f88812d705de8f572373d2abe5f195b.tar.gz
fix issue #255 and #256 empty collection defaulting to flow-style0.15.76
an empty collection now defaults to best style. I.e. if elements are inserted their style is not forced to flow-style *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))*
Diffstat (limited to 'representer.py')
-rw-r--r--representer.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/representer.py b/representer.py
index 28ec9a2..e0ac31d 100644
--- a/representer.py
+++ b/representer.py
@@ -895,7 +895,7 @@ class RoundTripRepresenter(SafeRepresenter):
best_style = False
value.append(node_item)
if flow_style is None:
- if self.default_flow_style is not None:
+ if len(sequence) != 0 and self.default_flow_style is not None:
node.flow_style = self.default_flow_style
else:
node.flow_style = best_style
@@ -961,11 +961,13 @@ class RoundTripRepresenter(SafeRepresenter):
except AttributeError:
item_comments = {}
merge_list = [m[1] for m in getattr(mapping, merge_attrib, [])]
+ item_count = 0
if bool(merge_list):
items = mapping.non_merged_items()
else:
items = mapping.items()
for item_key, item_value in items:
+ item_count += 1
node_key = self.represent_key(item_key)
node_value = self.represent_data(item_value)
item_comment = item_comments.get(item_key)
@@ -984,7 +986,8 @@ class RoundTripRepresenter(SafeRepresenter):
best_style = False
value.append((node_key, node_value))
if flow_style is None:
- if self.default_flow_style is not None:
+ if ((item_count != 0) or bool(merge_list)) \
+ and self.default_flow_style is not None:
node.flow_style = self.default_flow_style
else:
node.flow_style = best_style