You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I understand, using _file removes all existing keys at the same tree level and replaces them with the content of the file, like so:
# conf/base.yamlsub:
a: 1# Is removed when _file is loaded_file: update# conf/sub/update.yamlb: 2# Result:sub:
b: 2
What do you think about updating the existing dictionary with the file values instead? The result would then be:
# Result:sub:
a: 1b: 2
This would keep existing keys and would essentially work like default values for the loaded file, so that common values do not have to repeated in every file I could import.
The tree would ideally be updated recursively, so something like this might work:
+ def _update_recursively(node, key, update):+ if isinstance(node[key], dict) and isinstance(update, dict):+ for k, v in update.items():+ if k in node[key]:+ _update_recursively(node[key], k, v)+ else:+ node[key][k] = v+ else:+ node[key] = update
...
In https://github.com/mattiasarro/confr/blob/main/src/confr/models.py#L119
- conf_dict[k] = read_yaml(conf_fp, verbose=verbose)+ _update_recursively(conf_dict, k, read_yaml(conf_fp, verbose=verbose))+ del conf_dict[k]["_file"]
The text was updated successfully, but these errors were encountered:
Hey, I love this library!
As far as I understand, using
_file
removes all existing keys at the same tree level and replaces them with the content of the file, like so:What do you think about updating the existing dictionary with the file values instead? The result would then be:
This would keep existing keys and would essentially work like default values for the loaded file, so that common values do not have to repeated in every file I could import.
The tree would ideally be updated recursively, so something like this might work:
The text was updated successfully, but these errors were encountered: