diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-11-01 15:41:15 +0100 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-11-01 15:41:15 +0100 |
commit | e63c1e186f88812d705de8f572373d2abe5f195b (patch) | |
tree | d2ca9500cab4cadd16d8b75852a23f12a359966e /constructor.py | |
parent | 82a72a27c6ba866878fdebe7a70bd4a86f54e81d (diff) | |
download | ruamel.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 'constructor.py')
-rw-r--r-- | constructor.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/constructor.py b/constructor.py index 05fbb34..bf484e1 100644 --- a/constructor.py +++ b/constructor.py @@ -846,7 +846,7 @@ class Constructor(SafeConstructor): lobject_name = [name] try: __import__(module_name) - except ImportError: + except ImportError as exc: raise ConstructorError( 'while constructing a Python object', mark, @@ -1289,7 +1289,7 @@ class RoundTripConstructor(SafeConstructor): return value # merge = [] - merge_map_list = [] + merge_map_list = [] # type: List[Any] index = 0 while index < len(node.value): key_node, value_node = node.value[index] @@ -1494,25 +1494,28 @@ class RoundTripConstructor(SafeConstructor): # type: (Any) -> Any data = CommentedSeq() data._yaml_set_line_col(node.start_mark.line, node.start_mark.column) - if node.flow_style is True: - data.fa.set_flow_style() - elif node.flow_style is False: - data.fa.set_block_style() if node.comment: data._yaml_add_comment(node.comment) yield data data.extend(self.construct_rt_sequence(node, data)) + self.set_collection_style(data, node) def construct_yaml_map(self, node): # type: (Any) -> Any data = CommentedMap() data._yaml_set_line_col(node.start_mark.line, node.start_mark.column) + yield data + self.construct_mapping(node, data) + self.set_collection_style(data, node) + + def set_collection_style(self, data, node): + # type: (Any, Any) -> None + if len(data) == 0: + return if node.flow_style is True: data.fa.set_flow_style() elif node.flow_style is False: data.fa.set_block_style() - yield data - self.construct_mapping(node, data) def construct_yaml_object(self, node, cls): # type: (Any, Any) -> Any |