From 44f33876f1b7ca0e1670b6f6f2d52f2992673405 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Fri, 5 Apr 2019 22:05:13 +0200 Subject: optionally allow duplicate merge keys https://stackoverflow.com/questions/55540686/configuring-ruamel-yaml-to-allow-duplicate-keys reported by mamacdon --- CHANGES | 8 ++++++++ README.rst | 10 +++++++--- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- constructor.py | 8 ++++++++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 9b46ce2..ab457f6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +[0, 15, 91]: 2019-04-05 + - allowing duplicate keys would not work for merge keys (reported by mamacdon on + `StackOverflow `__ + +[0, 15, 91]: 2019-04-05 + - allowing duplicate keys would not work for merge keys (reported by mamacdon on + `StackOverflow `__ + [0, 15, 90]: 2019-04-04 - fix issue with updating `CommentedMap` from list of tuples (reported by `Peter Henry `__) diff --git a/README.rst b/README.rst index 54e3ba7..f359efc 100644 --- a/README.rst +++ b/README.rst @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.15.90 -:updated: 2019-04-04 +:version: 0.15.91 +:updated: 2019-04-05 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,10 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.91 (2019-04-05): + - allowing duplicate keys would not work for merge keys (reported by mamacdon on + `StackOverflow `__ + 0.15.90 (2019-04-04): - fix issue with updating `CommentedMap` from list of tuples (reported by `Peter Henry `__) @@ -74,7 +78,7 @@ ChangeLog 0.15.86 (2019-01-16): - reinsert merge key in its old position (reported by grumbler on - `__) + `StackOverflow `__) - fix for issue with non-ASCII anchor names (reported and fix provided by Dandaleon Flux via email) - fix for issue when parsing flow mapping value starting with colon (in pure Python only) diff --git a/__init__.py b/__init__.py index cb39f68..d1481e1 100644 --- a/__init__.py +++ b/__init__.py @@ -7,8 +7,8 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 15, 90), - __version__='0.15.90', + version_info=(0, 15, 91), + __version__='0.15.91', author='Anthon van der Neut', author_email='a.van.der.neut@ruamel.eu', description='ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order', # NOQA diff --git a/_doc/_static/pypi.svg b/_doc/_static/pypi.svg index eb22633..6bc0f5e 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.15.900.15.90 + pypipypi0.15.910.15.91 diff --git a/constructor.py b/constructor.py index 3f11c56..4e76f18 100644 --- a/constructor.py +++ b/constructor.py @@ -362,6 +362,10 @@ class SafeConstructor(BaseConstructor): key_node, value_node = node.value[index] if key_node.tag == u'tag:yaml.org,2002:merge': if merge: # double << key + if self.allow_duplicate_keys: + del node.value[index] + index += 1 + continue args = [ 'while constructing a mapping', node.start_mark, @@ -1330,6 +1334,10 @@ class RoundTripConstructor(SafeConstructor): key_node, value_node = node.value[index] if key_node.tag == u'tag:yaml.org,2002:merge': if merge_map_list: # double << key + if self.allow_duplicate_keys: + del node.value[index] + index += 1 + continue args = [ 'while constructing a mapping', node.start_mark, -- cgit v1.2.1