diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-10-17 17:10:46 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-10-17 17:10:46 +0200 |
commit | a0d4b1a7f4998aa1d8015cf78bd043682bc9105b (patch) | |
tree | 44f79b8dba29cde1eb5c7afbe2ac35a393ef0c95 /constructor.py | |
parent | 783c5c68171e5cfac583a1c49a1c66c9209c2211 (diff) | |
download | ruamel.yaml-a0d4b1a7f4998aa1d8015cf78bd043682bc9105b.tar.gz |
fix issue 251 error on multiple merge keys
Diffstat (limited to 'constructor.py')
-rw-r--r-- | constructor.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/constructor.py b/constructor.py index 2983414..8600c9f 100644 --- a/constructor.py +++ b/constructor.py @@ -353,6 +353,25 @@ class SafeConstructor(BaseConstructor): while index < len(node.value): key_node, value_node = node.value[index] if key_node.tag == u'tag:yaml.org,2002:merge': + if merge: # double << key + args = [ + 'while constructing a mapping', + node.start_mark, + 'found duplicate key "{}"'.format(key_node.value), + key_node.start_mark, + """ + To suppress this check see: + http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys + """, + """\ + Duplicate keys will become an error in future releases, and are errors + by default when using the new API. + """, + ] + if self.allow_duplicate_keys is None: + warnings.warn(DuplicateKeyFutureWarning(*args)) + else: + raise DuplicateKeyError(*args) del node.value[index] if isinstance(value_node, MappingNode): self.flatten_mapping(value_node) @@ -1275,6 +1294,25 @@ class RoundTripConstructor(SafeConstructor): while index < len(node.value): key_node, value_node = node.value[index] if key_node.tag == u'tag:yaml.org,2002:merge': + if merge_map_list: # double << key + args = [ + 'while constructing a mapping', + node.start_mark, + 'found duplicate key "{}"'.format(key_node.value), + key_node.start_mark, + """ + To suppress this check see: + http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys + """, + """\ + Duplicate keys will become an error in future releases, and are errors + by default when using the new API. + """, + ] + if self.allow_duplicate_keys is None: + warnings.warn(DuplicateKeyFutureWarning(*args)) + else: + raise DuplicateKeyError(*args) del node.value[index] if isinstance(value_node, MappingNode): merge_map_list.append((index, constructed(value_node))) |