Skip to content

Commit

Permalink
Clearer error when trying to use a relative interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
odelalleau committed Apr 1, 2021
1 parent c3f344b commit f52dbeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions omegaconf/built_in_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,17 @@ def _get_and_validate_dict_input(
if isinstance(in_dict, str):
# Path to an existing key in the config: use `select()`.
key = in_dict
if key.startswith("."):
raise NotImplementedError(
f"To use relative interpolations with `{resolver_name}`, please use "
f"the explicit interpolation syntax: ${{{resolver_name}:${{{key}}}}}"
)
in_dict = OmegaConf.select(
root, key, throw_on_missing=True, default=_DEFAULT_SELECT_MARKER_
)
if in_dict is _DEFAULT_SELECT_MARKER_:
raise ConfigKeyError(f"Key not found: '{key}'")
assert in_dict is not None

if not isinstance(in_dict, Mapping):
raise TypeError(
Expand Down
9 changes: 9 additions & 0 deletions tests/interpolation/built_in_resolvers/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def test_dict_keys(cfg: Any, key: Any, expected: Any) -> None:
),
id="type_error_dictconfig",
),
param(
{"foo": "${oc.dict.keys_or_values:.bar}", "bar": {"x": 0}},
"foo",
raises(
InterpolationResolutionError,
match=re.escape("NotImplementedError"),
),
id="relative_with_select",
),
],
)
def test_get_and_validate_dict_input(
Expand Down

0 comments on commit f52dbeb

Please sign in to comment.