omry / omegaconf

Flexible Python configuration system. The last one you will ever need.
BSD 3-Clause "New" or "Revised" License
1.88k stars 98 forks source link

feat: set flag `readonly` recursively #1124

Open MatteoVoges opened 10 months ago

MatteoVoges commented 10 months ago

Motivation

I want a function that sets a value for a flag (atm readonly, but can be extended for all / generic flags) recursively.

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

Tests will be added if the basic structure is confirmed.

Fixes

Fixes #1123

MatteoVoges commented 10 months ago

@odelalleau with this I get:

from omegaconf import OmegaConf

config = OmegaConf.create({"a": {"b": 1}})

OmegaConf.set_readonly(config.a, True)
OmegaConf.set_readonly_recursively(config, False)
print(OmegaConf.is_readonly(config.a))
# >>> False
odelalleau commented 10 months ago

Thanks! I would suggest to do it a bit differently to have a more generic implementation:

odelalleau commented 9 months ago

Thanks for the update -- overall looks good to me, but I won't have time to look at it in details until next week. We'll need to add a news fragment as well and update the documentation.

indigoviolet commented 3 months ago

@omry @odelalleau this is a blocker for #1102, would be great to get it in