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

pop and del should throw in struct mode #225

Closed
omry opened this issue Apr 22, 2020 · 5 comments · Fixed by #226
Closed

pop and del should throw in struct mode #225

omry opened this issue Apr 22, 2020 · 5 comments · Fixed by #226

Comments

@omry
Copy link
Owner

omry commented Apr 22, 2020

This is a behavior change. DictConfig pop and del should not be permitted in struct mode (and in structured mode) because it's inconsistent with the the expected behavior of classes.

@cuichenx
Copy link

What is the correct way to delete a key in DictConfig then?
del conf.some_key works if you know the key name, but what if the key is specified by a variable?

@odelalleau
Copy link
Collaborator

What is the correct way to delete a key in DictConfig then? del conf.some_key works if you know the key name, but what if the key is specified by a variable?

del cfg[variable_name]

@cuichenx
Copy link

del cfg[variable_name]

Doesn't work for me. I get omegaconf.errors.ConfigTypeError: DictConfig in struct mode does not support deletion
Unless this works in a newer version? I'm using 2.2.3

@odelalleau
Copy link
Collaborator

del cfg[variable_name]

Doesn't work for me. I get omegaconf.errors.ConfigTypeError: DictConfig in struct mode does not support deletion Unless this works in a newer version? I'm using 2.2.3

Any removal / addition will fail in struct mode, you can use the open_dict context manager to make it work (see https://omegaconf.readthedocs.io/en/2.3_branch/usage.html#struct-flag for an example of usage when adding a new key, but the same applies for deletion).

@cuichenx
Copy link

cuichenx commented Aug 3, 2023

Thanks for your reply.
I also found that cfg.__delattr__(key) works

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.

3 participants