summaryrefslogtreecommitdiff
path: root/constructor.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2021-06-09 15:29:00 +0200
committerAnthon van der Neut <anthon@mnt.org>2021-06-09 15:29:00 +0200
commit5a5b603289bfd9b9e1bcd57618cf8694bd0ec2aa (patch)
tree3244f3c128fbb54bfc57e06f309a3ea333a62938 /constructor.py
parent148949be5260969391a5b993cbb3fb602bed55a6 (diff)
downloadruamel.yaml-5a5b603289bfd9b9e1bcd57618cf8694bd0ec2aa.tar.gz
fix for issue 3870.17.8
tagged objects that have a templated (idNNN) anchor, did get the anchor added explicitly, resulting potentially in double anchors
Diffstat (limited to 'constructor.py')
-rw-r--r--constructor.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/constructor.py b/constructor.py
index 53a3d41..7392855 100644
--- a/constructor.py
+++ b/constructor.py
@@ -7,7 +7,7 @@ import re
import sys
import types
import warnings
-from collections.abc import Hashable, MutableSequence, MutableMapping # type: ignore
+from collections.abc import Hashable, MutableSequence, MutableMapping
# fmt: off
from ruamel.yaml.error import (MarkedYAMLError, MarkedYAMLFutureWarning,
@@ -16,7 +16,7 @@ from ruamel.yaml.nodes import * # NOQA
from ruamel.yaml.nodes import (SequenceNode, MappingNode, ScalarNode)
from ruamel.yaml.compat import (_F, builtins_module, # NOQA
nprint, nprintf, version_tnf)
-from ruamel.yaml.compat import ordereddict # type: ignore
+from ruamel.yaml.compat import ordereddict
from ruamel.yaml.comments import * # NOQA
from ruamel.yaml.comments import (CommentedMap, CommentedOrderedMap, CommentedSet,
@@ -1725,7 +1725,10 @@ class RoundTripConstructor(SafeConstructor):
data.yaml_set_tag(node.tag)
yield data
if node.anchor:
- data.yaml_set_anchor(node.anchor)
+ from ruamel.yaml.serializer import templated_id
+
+ if not templated_id(node.anchor):
+ data.yaml_set_anchor(node.anchor)
self.construct_mapping(node, data)
return
elif isinstance(node, ScalarNode):
@@ -1735,7 +1738,10 @@ class RoundTripConstructor(SafeConstructor):
data2.yaml_set_tag(node.tag)
yield data2
if node.anchor:
- data2.yaml_set_anchor(node.anchor, always_dump=True)
+ from ruamel.yaml.serializer import templated_id
+
+ if not templated_id(node.anchor):
+ data2.yaml_set_anchor(node.anchor, always_dump=True)
return
elif isinstance(node, SequenceNode):
data3 = CommentedSeq()
@@ -1747,7 +1753,10 @@ class RoundTripConstructor(SafeConstructor):
data3.yaml_set_tag(node.tag)
yield data3
if node.anchor:
- data3.yaml_set_anchor(node.anchor)
+ from ruamel.yaml.serializer import templated_id
+
+ if not templated_id(node.anchor):
+ data3.yaml_set_anchor(node.anchor)
data3.extend(self.construct_sequence(node))
return
except: # NOQA