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

Confusing behavior when setting a ConfigTree to a dictionary #380

Open
zmbc opened this issue Dec 11, 2023 · 1 comment
Open

Confusing behavior when setting a ConfigTree to a dictionary #380

zmbc opened this issue Dec 11, 2023 · 1 comment

Comments

@zmbc
Copy link
Contributor

zmbc commented Dec 11, 2023

Not sure if this is a bug per se, or a design issue, but I was very surprised by the output of this:

from vivarium import ConfigTree

config = ConfigTree()

config.update({'foo': {'bar': 'baz'}}, layer='base')

config.foo = {}

print(config)
print(config.foo)

The line config.foo = {} has no effect. I understand that this is consistent with .update, where dictionaries are used as the data model for nested keys and the update'd tree is merged into the current one, but setting an attribute feels like it should never be a no-op; it should either set something, or error.

@zmbc
Copy link
Contributor Author

zmbc commented Dec 11, 2023

The way __setattr__ behaves with dictionaries overall is a bit surprising, even when not a no-op. for example:

from vivarium import ConfigTree

config = ConfigTree(layers=['super_base', 'base'])

config.update({'foo': {'bar': 'baz', 'bar_2': 'baz_2'}}, layer='super_base')

config.foo = {'bar': 'quux'}

print(config)
print(config.foo)

The fact that config.foo = {'bar': 'quux'} acts like update and performs a merge is not obvious at all from the syntax.

@zmbc zmbc changed the title Confusing behavior when setting a ConfigTree to an empty dictionary Confusing behavior when setting a ConfigTree to a dictionary Dec 13, 2023
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

No branches or pull requests

1 participant