summaryrefslogtreecommitdiff
path: root/constructor.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-08-17 23:20:49 +0200
committerAnthon van der Neut <anthon@mnt.org>2016-08-17 23:20:49 +0200
commitf21343115c0b7f2849766f741bbe64e6c170a556 (patch)
tree9d6acdd6db9a3f8cb0ebead98d1233a5da1607cc /constructor.py
parentd8b794cccf8054a73ae61b6128e342b23b390e1d (diff)
downloadruamel.yaml-f21343115c0b7f2849766f741bbe64e6c170a556.tar.gz
added .keys(), items(), values(), corrected __contains__
There was a huge problem with 3.4 and 3.3 as the OrderedDict does not define a __contains__ and the implementation based on the one by Ngo would not work with merge keys defining keys that later were in the main dict (which should override). Fix was to add the merge key info at the point the dict has been completely created, thus restricting __contains__ automatically to the dict itself (and not test subkeys)
Diffstat (limited to 'constructor.py')
-rw-r--r--constructor.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/constructor.py b/constructor.py
index c86989a..a07a8e3 100644
--- a/constructor.py
+++ b/constructor.py
@@ -941,8 +941,6 @@ class RoundTripConstructor(SafeConstructor):
"expected a mapping node, but found %s" % node.id,
node.start_mark)
merge_map = self.flatten_mapping(node)
- if merge_map:
- maptyp.add_yaml_merge(merge_map)
# mapping = {}
if node.comment:
maptyp._yaml_add_comment(node.comment[:2])
@@ -981,6 +979,10 @@ class RoundTripConstructor(SafeConstructor):
key, [key_node.start_mark.line, key_node.start_mark.column,
value_node.start_mark.line, value_node.start_mark.column])
maptyp[key] = value
+ # do this last, or <<: before a key will prevent insertion in instances
+ # of collections.OrderedDict (as they have no __contains__
+ if merge_map:
+ maptyp.add_yaml_merge(merge_map)
def construct_setting(self, node, typ, deep=False):
if not isinstance(node, MappingNode):