Skip to content

Optionally allow keypath_separator in input dict keys (unflatten). #367

@brynpickering

Description

@brynpickering

We're loading in YAML files where we allow the dot notation in place of nested keys. Therefore, the keypath_separator is . and I'd like that to remain the separator in the resulting benedict.

Therefore: foo.bar: 1 should be loaded in as {'foo': {'bar': 1}} and then be accessible as my_dict["foo.bar"] and my_dict["foo"]["bar"].

Interestingly, in the currently benedict implementation, I can make this happen for top-level keys containing the keypath separator, as follows:

[In] 
my_dict = {"foo.bar": 1}
my_benedict = benedict()
my_benedict.merge(my_dict)
my_benedict

[Out] 
{'foo': {'bar': 1}}

But I get the (expected) error in these two cases:

benedict({"foo.bar": 1})
my_dict = {"baz": {"foo.bar": 1}}
my_benedict = benedict()
my_benedict.merge(my_dict)

python-benedict version: 0.33.1

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions