Skip to content

Commit

Permalink
Fix oc.dict.values behavior for relative dotpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasha10 committed May 26, 2022
1 parent 28e553a commit 72af2c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions omegaconf/resolvers/oc/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def values(key: str, _root_: BaseContainer, _parent_: Container) -> ListConfig:
assert isinstance(content, dict)

ret = ListConfig([])
if key.startswith("."):
key = f".{key}" # extra dot to compensate for extra level of nesting within ret ListConfig
for k in content:
ref_node = AnyNode(f"${{{key}.{k!s}}}")
ret.append(ref_node)
Expand Down
30 changes: 30 additions & 0 deletions tests/interpolation/built_in_resolvers/test_oc_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,36 @@ def test_readonly_parent(cfg: Any, expected: Any) -> None:
assert cfg.x == expected


@mark.parametrize(
("cfg", "expected"),
[
param(
{"outer": {"x": "${oc.dict.values:.y}", "y": {"a": 1}}},
[1],
id="values_inter",
),
param(
{"outer": {"x": "${oc.dict.keys:.y}", "y": {"a": 1}}},
["a"],
id="keys_inter",
),
param(
{"outer": {"x": "${oc.dict.values:..y}"}, "y": {"a": 1}},
[1],
id="parent_values_inter",
),
param(
{"outer": {"x": "${oc.dict.keys:..y}"}, "y": {"a": 1}},
["a"],
id="parent_keys_inter",
),
],
)
def test_relative_path(cfg: Any, expected: Any) -> None:
cfg = OmegaConf.create(cfg)
assert cfg.outer.x == expected


@mark.parametrize(
("cfg", "expected"),
[
Expand Down

0 comments on commit 72af2c7

Please sign in to comment.