Skip to content

Commit

Permalink
Nested flag_override now properly restore the orignal state (omry#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
omry authored Mar 9, 2021
1 parent e039e5b commit d9c3b01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/589.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nested flag_override now properly restore the orignal state
2 changes: 1 addition & 1 deletion omegaconf/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def flag_override(
if values is None or isinstance(values, bool):
values = [values]

prev_states = [config._get_flag(name) for name in names]
prev_states = [config._get_node_flag(name) for name in names]

try:
config._set_flag(names, values)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ def test_flag_override(
func(c)


def test_nested_flag_override() -> None:
c = OmegaConf.create({"a": {"b": 1}})
with flag_override(c, "test", True):
assert c._get_flag("test") is True
with flag_override(c.a, "test", False):
assert c.a._get_flag("test") is False
assert c.a._get_flag("test") is None


def test_multiple_flags_override() -> None:
c = OmegaConf.create({"foo": "bar"})
with flag_override(c, ["readonly"], True):
Expand Down

0 comments on commit d9c3b01

Please sign in to comment.