-
Notifications
You must be signed in to change notification settings - Fork 56
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 perform a deep copy
#1714
Comments
Related to this, a callback that modifies a non-dict/non-list node modifies the input. import asdf
class Foo:
pass
tree = {'f': Foo()}
assert not hasattr(tree['f'], 'bar')
def callback(obj):
if isinstance(obj, Foo):
obj.bar = 1
return obj
asdf.treeutil.walk_and_modify(tree, callback)
assert hasattr(tree['f'], 'bar')
assert tree['f'].bar == 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description of the problem
asdf.treeutil.walk_and_modify documentation states:
However the function does not perform a deep copy. For the below example the
callback
will be called 3 times:arr
, the same instance that is in the tree{'arr': arr}
a different instance than the dictionarytree['a']
{'a': {'arr': arr}}
a different instance than the dictionarytree
To summarize, the leaf object
arr
is not copied but all container objects (dicts in this case) are "copied".Example of the problem
System information
asdf version: main branch
python version: 3.10
operating system: mac osx
The text was updated successfully, but these errors were encountered: