summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-06-09 07:07:18 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-06-09 07:07:18 +0200
commitcb15ef0ad512c00584ff4195ca88334d1f2b0fa6 (patch)
tree71839804b30b9c92c4a2d8243529c4704de5cf30
parent4b847b7d4706726c3a32f158fd480e61b6c3019f (diff)
downloadruamel.yaml-cb15ef0ad512c00584ff4195ca88334d1f2b0fa6.tar.gz
rt set handling now checks for duplicate keys
-rw-r--r--README.rst3
-rw-r--r--__init__.py4
-rw-r--r--_test/test_api_change.py15
-rw-r--r--constructor.py4
4 files changed, 23 insertions, 3 deletions
diff --git a/README.rst b/README.rst
index f5130b0..6422b7c 100644
--- a/README.rst
+++ b/README.rst
@@ -32,6 +32,9 @@ ChangeLog
.. should insert NEXT: at the beginning of line for next key
+NEXT:
+ - a set with duplicate elements now throws error in rt loading
+
0.15.5 (2017-06-08):
- repeat `load()` on a single `YAML()` instance would fail.
diff --git a/__init__.py b/__init__.py
index d8bd99c..037bed1 100644
--- a/__init__.py
+++ b/__init__.py
@@ -11,8 +11,8 @@ if False: # MYPY
_package_data = dict(
full_package_name='ruamel.yaml',
- version_info=(0, 15, 5),
- __version__='0.15.5',
+ version_info=(0, 15, 6, 'dev'),
+ __version__='0.15.6.dev',
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/_test/test_api_change.py b/_test/test_api_change.py
index e33e8bc..bd56881 100644
--- a/_test/test_api_change.py
+++ b/_test/test_api_change.py
@@ -7,6 +7,7 @@ testing of anchors and the aliases referring to them
"""
import sys
+import textwrap
import pytest
from ruamel.yaml import YAML
from ruamel.yaml.constructor import DuplicateKeyError
@@ -97,3 +98,17 @@ class TestRead:
yaml = YAML()
yaml.load('a: 1')
yaml.load('a: 1') # did not work in 0.15.4
+
+
+class TestDuplSet:
+ def test_dupl_set_00(self):
+ # round-trip-loader should except
+ yaml = YAML()
+ with pytest.raises(DuplicateKeyError):
+ yaml.load(textwrap.dedent("""\
+ !!set
+ ? a
+ ? b
+ ? c
+ ? a
+ """))
diff --git a/constructor.py b/constructor.py
index 83cbbec..a37f794 100644
--- a/constructor.py
+++ b/constructor.py
@@ -246,7 +246,7 @@ class BaseConstructor(object):
"while constructing a mapping", node.start_mark,
'found duplicate key "{}" with value "{}" '
'(original value: "{}")'.format(
- key, value, mapping[key]), key_node.start_mark,
+ key, value, mapping.get(key)), key_node.start_mark,
"""
To suppress this check see:
http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys
@@ -1243,7 +1243,9 @@ class RoundTripConstructor(SafeConstructor):
raise ConstructorError(
"while constructing a mapping", node.start_mark,
"found unhashable key", key_node.start_mark)
+ # construct but should be null
value = self.construct_object(value_node, deep=deep) # NOQA
+ self.check_mapping_key(node, key_node, typ, key, value)
if key_node.comment:
typ._yaml_add_comment(key_node.comment, key=key)
if value_node.comment: