Skip to content

Commit 291528b

Browse files
authored
Merge pull request #1907 from braingram/load_yaml_tagged
use yaml constructors for _IgnoreCustomTagsLoader
2 parents 74fdcd9 + fc001f6 commit 291528b

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

asdf/_tests/test_util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,21 @@ def test_load_yaml_recursion(tmp_path, tagged):
128128
tree = util.load_yaml(fn, tagged=tagged)
129129
assert tree["d"]["d"] is tree["d"]
130130
assert tree["l"][0] is tree["l"]
131+
132+
133+
@pytest.mark.parametrize("tagged", [True, False])
134+
def test_load_yaml_recursion_with_tags(tagged):
135+
contents = b"""#ASDF 1.0.0
136+
#ASDF_STANDARD 1.6.0
137+
%YAML 1.1
138+
%TAG ! tag:stsci.edu:asdf/
139+
--- !core/asdf-1.1.0
140+
o: &id001 !some/tag-1.0.0
141+
inverse: !some/tag-1.0.0
142+
inverse: *id001
143+
l: &id002 !some/tag-1.0.0
144+
- *id002
145+
..."""
146+
tree = util.load_yaml(io.BytesIO(contents), tagged=tagged)
147+
assert tree["o"] is tree["o"]["inverse"]["inverse"]
148+
assert tree["l"] is tree["l"][0]

asdf/yamlutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ class _IgnoreCustomTagsLoader(_yaml_base_loader):
147147

148148
def construct_undefined(self, node):
149149
if isinstance(node, yaml.MappingNode):
150-
return self.construct_mapping(node)
150+
return self.construct_yaml_map(node)
151151
elif isinstance(node, yaml.SequenceNode):
152-
return self.construct_sequence(node)
152+
return self.construct_yaml_seq(node)
153153
elif isinstance(node, yaml.ScalarNode):
154154
return self.construct_scalar(node)
155155
return super().construct_undefined(node)

changes/1907.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support recursive tagged nodes in load_yaml.

0 commit comments

Comments
 (0)