diff options
author | Anthon van der Neut <anthon@mnt.org> | 2019-01-08 09:03:34 +0100 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2019-01-08 09:03:34 +0100 |
commit | bdc07310846d253ddeac78f370db03df5d6e31b0 (patch) | |
tree | 960e48a41009998f6d1c32e6fb72930963672106 /constructor.py | |
parent | 619842506decc4b036e06e5753f3f7476c036d41 (diff) | |
download | ruamel.yaml-bdc07310846d253ddeac78f370db03df5d6e31b0.tar.gz |
resolves issue #274 replace dict with collections.OrderedDict when loading0.15.85
https://bitbucket.org/ruamel/yaml/issues/274/add-a-typ-ordered-for-a-middle-ground#comment-49783394
*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 | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/constructor.py b/constructor.py index 65d6829..53e0d27 100644 --- a/constructor.py +++ b/constructor.py @@ -63,6 +63,8 @@ class BaseConstructor(object): if self.loader is not None and getattr(self.loader, '_constructor', None) is None: self.loader._constructor = self self.loader = loader + self.yaml_base_dict_type = dict + self.yaml_base_list_type = list self.constructed_objects = {} # type: Dict[Any, Any] self.recursive_objects = {} # type: Dict[Any, Any] self.state_generators = [] # type: List[Any] @@ -207,13 +209,13 @@ class BaseConstructor(object): raise ConstructorError( None, None, 'expected a mapping node, but found %s' % node.id, node.start_mark ) - total_mapping = {} + total_mapping = self.yaml_base_dict_type() if getattr(node, 'merge', None) is not None: todo = [(node.merge, False), (node.value, False)] else: todo = [(node.value, True)] for values, check in todo: - mapping = {} # type: Dict[Any, Any] + mapping = self.yaml_base_dict_type() # type: Dict[Any, Any] for key_node, value_node in values: # keys can be list -> deep key = self.construct_object(key_node, deep=True) @@ -686,13 +688,13 @@ class SafeConstructor(BaseConstructor): def construct_yaml_seq(self, node): # type: (Any) -> Any - data = [] # type: List[Any] + data = self.yaml_base_list_type() # type: List[Any] yield data data.extend(self.construct_sequence(node)) def construct_yaml_map(self, node): # type: (Any) -> Any - data = {} # type: Dict[Any, Any] + data = self.yaml_base_dict_type() # type: Dict[Any, Any] yield data value = self.construct_mapping(node) data.update(value) |