Skip to content

Commit

Permalink
add AsdfOrderedDictNode
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Jan 8, 2024
1 parent 3d06a10 commit 48262db
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions asdf/_lazy_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def _convert(value, af_ref):
data = value.data
if isinstance(data, dict):
data = AsdfDictNode(data, af_ref)
elif isinstance(data, collections.OrderedDict):
data = AsdfOrderedDictNode(data, af_ref)
elif isinstance(data, list):
data = AsdfListNode(data, af_ref)
obj = converter.from_yaml_tree(data, tag, sctx)
Expand Down Expand Up @@ -116,7 +118,10 @@ def __getitem__(self, key):
if value_id in af._tagged_object_cache:
value = af._tagged_object_cache[value_id][1]
else:
obj = AsdfDictNode(value, self._af_ref)
if type(value) == collections.OrderedDict:
obj = AsdfOrderedDictNode(value, self._af_ref)
else:
obj = AsdfDictNode(value, self._af_ref)
af._tagged_object_cache[value_id] = (value, obj)
value = obj
self[key] = value
Expand Down Expand Up @@ -173,8 +178,15 @@ def __getitem__(self, key):
if value_id in af._tagged_object_cache:
value = af._tagged_object_cache[value_id][1]
else:
obj = AsdfDictNode(value, self._af_ref)
if type(value) == collections.OrderedDict:
obj = AsdfOrderedDictNode(value, self._af_ref)
else:
obj = AsdfDictNode(value, self._af_ref)
af._tagged_object_cache[value_id] = (value, obj)
value = obj
self[key] = value
return value


class AsdfOrderedDictNode(AsdfDictNode, collections.OrderedDict):
pass

0 comments on commit 48262db

Please sign in to comment.