Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asdf.treeutil.walk_and_modify does not remove nodes in list #1720

Open
braingram opened this issue Dec 28, 2023 · 0 comments · May be fixed by #1721
Open

asdf.treeutil.walk_and_modify does not remove nodes in list #1720

braingram opened this issue Dec 28, 2023 · 0 comments · May be fixed by #1721

Comments

@braingram
Copy link
Contributor

braingram commented Dec 28, 2023

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

@braingram braingram linked a pull request Jan 3, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant