How to use the omegaconf.OmegaConf.set_readonly function in omegaconf

To help you get started, we’ve selected a few omegaconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github omry / omegaconf / tests / test_readonly.py View on Github external
def test_readonly_flag(src: Union[Dict[str, Any], List[Any]]) -> None:
    c = OmegaConf.create(src)
    assert not OmegaConf.is_readonly(c)
    OmegaConf.set_readonly(c, True)
    assert OmegaConf.is_readonly(c)
    OmegaConf.set_readonly(c, False)
    assert not OmegaConf.is_readonly(c)
    OmegaConf.set_readonly(c, None)
    assert not OmegaConf.is_readonly(c)
github omry / omegaconf / tests / test_errors.py View on Github external
def create_readonly(cfg: Any) -> Any:
    cfg = OmegaConf.create(cfg)
    OmegaConf.set_readonly(cfg, True)
    return cfg
github omry / omegaconf / tests / test_readonly.py View on Github external
def test_readonly_list_del() -> None:
    c = OmegaConf.create([1, 2, 3])
    assert isinstance(c, ListConfig)
    OmegaConf.set_readonly(c, True)
    with raises(ReadonlyConfigError, match="[1]"):
        del c[1]
    assert c == [1, 2, 3]
github omry / omegaconf / tests / test_merge.py View on Github external
def test_with_readonly_c1(c1: Any, c2: Any) -> None:
    cfg1 = OmegaConf.create(c1)
    cfg2 = OmegaConf.create(c2)
    OmegaConf.set_readonly(cfg1, True)
    cfg3 = OmegaConf.merge(cfg1, cfg2)
    assert OmegaConf.is_readonly(cfg3)
github omry / omegaconf / tests / test_readonly.py View on Github external
def test_readonly_list_change_item() -> None:
    c = OmegaConf.create([1, 2, 3])
    assert isinstance(c, ListConfig)
    OmegaConf.set_readonly(c, True)
    with raises(ReadonlyConfigError, match="[1]"):
        c[1] = 10
    assert c == [1, 2, 3]
github omry / omegaconf / tests / test_readonly.py View on Github external
def test_readonly_flag(src: Union[Dict[str, Any], List[Any]]) -> None:
    c = OmegaConf.create(src)
    assert not OmegaConf.is_readonly(c)
    OmegaConf.set_readonly(c, True)
    assert OmegaConf.is_readonly(c)
    OmegaConf.set_readonly(c, False)
    assert not OmegaConf.is_readonly(c)
    OmegaConf.set_readonly(c, None)
    assert not OmegaConf.is_readonly(c)
github omry / omegaconf / tests / test_merge.py View on Github external
def test_dict_merge_readonly_into_readwrite(c1: Any, c2: Any, expected: Any) -> None:
    c1 = OmegaConf.create(c1)
    c2 = OmegaConf.create(c2)
    OmegaConf.set_readonly(c2.node, True)
    with pytest.raises(ReadonlyConfigError):
        c2.node.foo = 10
    assert OmegaConf.merge(c1, c2) == expected
    c1.merge_with(c2)
    assert c1 == expected
github omry / omegaconf / tests / test_merge.py View on Github external
def test_with_readonly_c2(c1: Any, c2: Any) -> None:
    cfg1 = OmegaConf.create(c1)
    cfg2 = OmegaConf.create(c1)
    OmegaConf.set_readonly(cfg2, True)
    cfg3 = OmegaConf.merge(cfg1, cfg2)
    assert OmegaConf.is_readonly(cfg3)
github facebookresearch / hydra / hydra / plugins / common / utils.py View on Github external
def set_config(self, cfg):
        try:
            OmegaConf.set_readonly(self, False)
            self.hydra = copy.deepcopy(cfg.hydra)
        finally:
            OmegaConf.set_readonly(self, True)
github shagunsodhani / torch-template / codes / utils / config.py View on Github external
def make_config_immutable(config: ConfigType) -> ConfigType:
    """Set the config to be immutable

    Args:
        config (ConfigType):

    Returns:
        ConfigType:
    """
    OmegaConf.set_readonly(config, True)
    return config