summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2015-07-04 16:41:36 +0200
committerAnthon van der Neut <anthon@mnt.org>2015-07-04 16:41:36 +0200
commitf74c504f870e37eb0148dc1d0533440026c5dae5 (patch)
tree478daa17a64ac96972cc3fa74215c67e0207da14
parent52aea5baaaf1fbfc7602228cb82a269e1449ec43 (diff)
downloadruamel.yaml-f74c504f870e37eb0148dc1d0533440026c5dae5.tar.gz
fix issue with anchors on sequences (reported by Bjorn Stabell)
https://bitbucket.org/ruamel/yaml/issue/7/anchor-names-not-preserved
-rw-r--r--py/__init__.py2
-rw-r--r--py/constructor.py8
-rw-r--r--test/test_anchor.py20
3 files changed, 29 insertions, 1 deletions
diff --git a/py/__init__.py b/py/__init__.py
index 1c14001..0e8b561 100644
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -21,7 +21,7 @@ def _convert_version(tup):
return ret_val
-version_info = (0, 10, 1)
+version_info = (0, 10, 2)
__version__ = _convert_version(version_info)
del _convert_version
diff --git a/py/constructor.py b/py/constructor.py
index bfcd17d..1de8545 100644
--- a/py/constructor.py
+++ b/py/constructor.py
@@ -835,6 +835,10 @@ class RoundTripConstructor(SafeConstructor):
seqtyp._yaml_add_comment(node.comment[:2])
if len(node.comment) > 2:
seqtyp.yaml_end_comment_extend(node.comment[2], clear=True)
+ if node.anchor:
+ from ruamel.yaml.serializer import templated_id
+ if not templated_id(node.anchor):
+ seqtyp.yaml_set_anchor(node.anchor)
for idx, child in enumerate(node.value):
ret_val.append(self.construct_object(child, deep=deep))
if child.comment:
@@ -949,6 +953,10 @@ class RoundTripConstructor(SafeConstructor):
typ._yaml_add_comment(node.comment[:2])
if len(node.comment) > 2:
typ.yaml_end_comment_extend(node.comment[2], clear=True)
+ if node.anchor:
+ from ruamel.yaml.serializer import templated_id
+ if not templated_id(node.anchor):
+ typ.yaml_set_anchor(node.anchor)
for key_node, value_node in node.value:
# keys can be list -> deep
key = self.construct_object(key_node, deep=True)
diff --git a/test/test_anchor.py b/test/test_anchor.py
index 422b9d6..efbcb21 100644
--- a/test/test_anchor.py
+++ b/test/test_anchor.py
@@ -105,6 +105,26 @@ class TestAnchorsAliases:
c: 2
""")
+ def test_anchor_on_sequence(self):
+ # as reported by Bjorn Stabell
+ # https://bitbucket.org/ruamel/yaml/issue/7/anchor-names-not-preserved
+ from ruamel.yaml.comments import CommentedSeq
+ data = load("""
+ nut1: &alice
+ - 1
+ - 2
+ nut2: &blake
+ - some data
+ - *alice
+ nut3:
+ - *blake
+ - *alice
+ """)
+ l = data['nut1']
+ assert isinstance(l, CommentedSeq)
+ assert l.yaml_anchor() is not None
+ assert l.yaml_anchor().value == 'alice'
+
merge_yaml = dedent("""
- &CENTER {x: 1, y: 2}