asdf-format/asdf

`asdf.treeutil.walk_and_modify` does not remove nodes in list

Opened this issue · 0 comments

Description of the problem

Returning asdf.treeutil.RemoveNode from a callback that is processing an item that is part of a list does not result in removal of the node.

Example of the problem

import asdf

tree = {"a": [1, 2], "b": 2}

def callback(obj):
    if obj == 2:
        return asdf.treeutil.RemoveNode
    return obj

new_tree = asdf.treeutil.walk_and_modify(tree, callback)
print(new_tree)
assert "b" not in new_tree
assert "a" in new_tree
assert new_tree["a"][0] == 1
assert new_tree["a"][1] == asdf.treeutil.RemoveNode  # this should not exist

The above example prints out:

{'a': [1, RemoveNode]}

System information

asdf version: main
python version: 3.10
operating system: mac os