Skip to content

Commit ecbe098

Browse files
committed
Warn on unknown configuration keys
1 parent e525546 commit ecbe098

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

kraken/ketos/util.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import yaml
2424
import shlex
2525
import logging
26+
import difflib
2627
from collections import defaultdict
2728
from typing import Optional, Any, TYPE_CHECKING
2829

@@ -53,14 +54,20 @@ def _recursive_update(a: dict[str, Any],
5354
b: dict[str, Any]) -> dict[str, Any]:
5455
"""Like standard ``dict.update()``, but recursive so sub-dict gets updated.
5556
56-
Ignore elements present in ``b`` but not in ``a``. Unless ``strict`` is set to
57-
`True`, in which case a `ValueError` exception will be raised.
57+
Warns on keys present in ``b`` but not in ``a`` and suggests alternatives.
5858
"""
5959
for k, v in b.items():
60+
if k not in a:
61+
matches = difflib.get_close_matches(k, a.keys())
62+
msg = f'Ignoring unknown configuration key "{k}" in experiment file.'
63+
if matches:
64+
msg += f' Did you mean "{matches[0]}"?'
65+
logger.warning(msg)
66+
continue
6067
if isinstance(v, dict) and isinstance(a.get(k), dict):
6168
a[k] = _recursive_update(a[k], v)
6269
else:
63-
a[k] = b[k]
70+
a[k] = v
6471
return a
6572

6673

0 commit comments

Comments
 (0)